我想处理这个表单(valueChangeListener 在实际情况下无效)。
这是后面的bean:
@Component
@Scope("request")
public class TestBean extends PrivateBaseBean implements Serializable {
protected static final Logger logger = Utils.loggerForThisClass();
private TreeNode root;
@PostConstruct
public void init() {
root = new DefaultTreeNode("root", null);
TreeNode child1 = new DefaultTreeNode(new Element("Total"), root);
new DefaultTreeNode(new Element("Office"), child1);
}
public void saveAction() {
StringBuilder textToShowInMessage = new StringBuilder();
for (TreeNode children : root.getChildren()) {
logger.debug(((Element) children.getData()).getName() + "->"
+ ((Element) children.getData()).getValue());
for (TreeNode leaf : children.getChildren()) {
logger.debug(((Element) leaf.getData()).getName() + "->"
+ ((Element) leaf.getData()).getValue());
}
}
}
public TreeNode getRoot() {
return root;
}
public void setRoot(TreeNode root) {
this.root = root;
}
元件型号:
public class Element {
private String name;
private String value;
public Element(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
最后是观点:
<h:form>
<p:treeTable value="#{testBean.root}" var="element">
<p:column>
<f:facet name="header">
Name
</f:facet>
#{element.name}
</p:column>
<p:column>
<f:facet name="header">
Value
</f:facet>
<h:inputText value="#{element.value}" />
</p:column>
</p:treeTable>
<p:commandButton value="#{msg.save}" action="#{testBean.saveAction}"
process="@all" icon="ui-icon-disk" update="@form" />
</h:form>
我也想处理 TreeNode 中的所有表单值。但是Backing bean中只接收第一个childresn的第一个值。
这是输入:
这是输出:
DEBUG: com.smf.web.jsf.bean.TestBean - Total->1231231231
DEBUG: com.smf.web.jsf.bean.TestBean - Office->null
我不知道如何处理所有树值...