Tree Node and Ampersand

Hi,

I need to place ampersands in tree node text property. To get the text

rendered right I need to provide the text as, for example, Bed '&+amp+;'

Breakfast.

This tree node is rendering well in the browser as "Bed & Breakfast".

But if an action is associated with the tree node and I run the app

the tree node is rendering to "Bed '&+amp+;' Breakfast".

"&+amp+;" means the well formed XHTML for ampersand, if I had written this as it should be it would render in this post as &.

Is there any workaround?

Thanks.

Stephan

[612 byte] By [bardubitzkia] at [2007-11-26 19:41:42]
# 1
Hi,You can omit the xhtml workaround and set text in the prerender method.Then an associated action method will not affect the text./krys
3431603a at 2007-7-9 22:23:09 > top of Java-index,Development Tools,Java Tools...
# 2
Thanks for tip, much appreciated.Stephan
bardubitzkia at 2007-7-9 22:23:09 > top of Java-index,Development Tools,Java Tools...
# 3

The Tree Node is now rendering right, but I run into another problem. After selection I need to display the Tree Node text in a static text component. which worked with this code:

public String node_action() {

String fullId = tree1.getCookieSelectedTreeNode();

String id = fullId.substring(fullId.lastIndexOf(":")+1);

TreeNode selectedNode = (TreeNode) this.getForm1().findComponentById(id);

String category = selectedNode.getParentTreeNode((TreeNode) selectedNode).getText();

if ( category.indexOf("&") != -1 ) {

getSessionBean1().getClassified().setCategory(category.replace("&", "&"));

}

else {

getSessionBean1().getClassified().setCategory(category);

}

String subCategory = selectedNode.getText();

if ( subCategory.indexOf("&") != -1 ) {

getSessionBean1().getClassified().setSubCategory(subCategory.replace("&", "&"));

}

else {

getSessionBean1().getClassified().setSubCategory(subCategory);

}

categoryTextfield.setText(getSessionBean1().getClassified().getSubCategory());

categoryTextfield.setVisible(true);

return null;

}

}

(some & in the code section are original meant to be the XHTML for ampersand.)

but for the few Tree Nodes which are prerendered now, the call

String subCategory = selectedNode.getText();

returns null.

How can I get the text of for those prerendered Tree Node?

Thanks.

Stephan

bardubitzkia at 2007-7-9 22:23:09 > top of Java-index,Development Tools,Java Tools...
# 4

It depends on when you invoke selectedNode.getText(). If it is before prerender() is called, it may returns null. I'd suggest to bind the tree node's text property with a bean property which has the string "Bed & Breakfast"

<ui:treeNode action="#{Page1.treeNode1_action}"

binding="#{Page1.treeNode1}" id="treeNode1"

text="#{SessionBean1.treeNode1Test}">

<f:facet name="image">

<ui:image binding="#{Page1.image1}"

icon="TREE_DOCUMENT" id="image1"/>

</f:facet>

</ui:treeNode>

Sherry

sherryza at 2007-7-9 22:23:09 > top of Java-index,Development Tools,Java Tools...
# 5
Instead of putting the text property in to the sessionbean I had it in the pagebean, After placing it into the sessionbean it is working.Thanks.Stephan
bardubitzkia at 2007-7-9 22:23:09 > top of Java-index,Development Tools,Java Tools...