• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error while Spliting

 
Matt Hardy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to view the right side values from the properties in "nodeTitle" but I am facing an error ArrayIndexOutOfBoundsException....


This is my



Bean page:
public class SimpleTreeBean {


private TreeNode rootNode = null;
private List<String> selectedNodeChildren = new ArrayList<String>();

private String nodeTitle;
private String nodeTitle1;

private static final String DATA_PATH = "/pages/Tree/labeltree.properties";

private void addNodes(String path, TreeNode node, Properties properties) {
boolean end = false;
int counter = 1;

while (!end) {
String key = path != null ? path + '.' + counter : String.valueOf(counter);

String value = properties.getProperty(key);


if (value != null) {

String delimiter = "-";
String temp1 = value;
String temp[];
temp = temp1.split(delimiter);

value= temp[0];

TreeNodeImpl nodeImpl = new TreeNodeImpl();
nodeImpl.setData(value);

node.addChild(new Integer(counter), nodeImpl);
addNodes(key, nodeImpl, properties);
counter++;
} else {
end = true;
}
}
}

private void loadTree() {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH);
try {
Properties properties = new Properties();
properties.load(dataStream);

rootNode = new TreeNodeImpl();
addNodes(null, rootNode, properties);

} catch (IOException e) {
throw new FacesException(e.getMessage(), e);
} finally {
if (dataStream != null) {
try {
dataStream.close();
} catch (IOException e) {
externalContext.log(e.getMessage(), e);
}
}
}
}

public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getComponent();
nodeTitle = (String) tree.getRowData();

String delimiter = "-";
String temp1 = nodeTitle.toString();
String temp[];
temp = temp1.split(delimiter);


nodeTitle= temp[1];




selectedNodeChildren.clear();
TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
if (currentNode.isLeaf()){
selectedNodeChildren.add((String)currentNode.getData());
}else
{
Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
while (it!=null &&it.hasNext()) {
Map.Entry<Object, TreeNode> entry = it.next();
selectedNodeChildren.add(entry.getValue().getData().toString());
}
}
}

public TreeNode getTreeNode() {
if (rootNode == null) {
loadTree();
}

return rootNode;
}

public String getNodeTitle() {
return nodeTitle;
}

public void setNodeTitle(String nodeTitle) {
this.nodeTitle = nodeTitle;
}

public String getNodeTitle1() {
return nodeTitle1;
}

public void setNodeTitle1(String nodeTitle1) {
this.nodeTitle1 = nodeTitle1;
}

public String goTree() {
System.out.println("tree");
return "tree";
}

}






tree.html page -->



<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<title>Help Desk</title>
<style>
.col, .col2 {
width:50%;
vertical-align:top;
}
</style>


<h:form>
<div style="width: 100%; height: 4080px; background-color: #E8EDF0">
<div style="height: 45px; background-color: #A9DDEB">
<center>
<h4 style="font-size: 25px; color: #A9A9A9">Help Desk</h4>
</center>
</div>
<br/>
<h:panelGrid columns="2" width="100%" columnClasses="col1,col2">

<rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean.processSelection}"
reRender="selectedNode" ajaxSubmitSelection="true" switchType="client"
value="#{simpleTreeBean.treeNode}" var="item" ajaxKeys="#{null}">


</rich:tree>

<hutputText escape="false" style="font-size: 25px; color: #BC8F8F" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" />

</h:panelGrid>
</div>
</h:form>

</ui:composition>







Properties page


1=Administration - The Administration is
1.1=Configuration - The Configuration is
1.1.1=Company - The Company is
1.1.1.1=Head Office - The Head Office is
1.1.1.1.1=Head Office - The Head Office is




 
Matt Hardy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please reply. How to get rid of this problem?
 
Matt Hardy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any Suggestions?
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Hardy wrote:Any Suggestions?


A few.

http://www.coderanch.com/how-to/java/PatienceIsAVirtue

http://www.coderanch.com/how-to/java/UseCodeTags
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a little hard to read all that code on my monitor, but since the main problem is actually a plain old indexing issue, I'd consider beeing up the "split" function.


 
Matt Hardy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response Mr.Tim


My Bean...






tree.html




LabelProperties



Actually I want to view the right side details from the LabelProperties in "Selected Node: #{simpleTreeBean.nodeTitle}" ..... For eg: "The Administration is " in the page while on-clicking "Administration"...

Could you please help me?

Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!