• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Error while Spliting

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>

<h:outputText 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any Suggestions?
 
Saloon Keeper
Posts: 23884
162
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Hardy wrote:Any Suggestions?



A few.

https://coderanch.com/how-to/java/PatienceIsAVirtue

https://coderanch.com/how-to/java/UseCodeTags
 
Tim Holloway
Saloon Keeper
Posts: 23884
162
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic