不处理h:inputText在p:tabView中的值

时间:2013-05-15 11:20:51

标签: java jsf primefaces

我想处理这个表单(valueChangueListener在实际情况下无效)。

这是后豆:

private List<Management> managements; //getters setters
protected static final Logger logger = Utils.loggerForThisClass();

@PostConstruct
public void init() {
    TreeNode root1 = new DefaultTreeNode("root", null);
    TreeNode root2 = new DefaultTreeNode("root", null);
    TreeNode root3 = new DefaultTreeNode("root", null);

    TreeNode child1 = new DefaultTreeNode(new Element("Total"), root1);
    TreeNode child2 = new DefaultTreeNode(new Element("Total"), root2);
    TreeNode child3 = new DefaultTreeNode(new Element("Total"), root3);

    new DefaultTreeNode(new Element("Office"), child1);
    new DefaultTreeNode(new Element("Office"), child2);
    new DefaultTreeNode(new Element("Office"), child3);

    managements = new ArrayList<Management>();
    managements.add(new Management("Company1", root1));
    managements.add(new Management("Company2", root2));
    managements.add(new Management("Company3", root3));
}

public void saveAction() {

    StringBuilder textToShowInMessage = new StringBuilder();
    for (Management management : managements) {
        for (TreeNode children : management.getElementTree().getChildren()) {
            logger.debug(management.getTabTitle() + "->"
                    + ((Element) children.getData()).getName() + "->"
                    + ((Element) children.getData()).getValue());
            for (TreeNode leaf : children.getChildren()) {
                logger.debug(management.getTabTitle() + "->"
                        + ((Element) leaf.getData()).getName() + "->"
                        + ((Element) leaf.getData()).getValue());
            }
        }
    }
} ...

模特:

public class Management {
private String tabTitle;
private TreeNode elementTree;

public Management(String tabTitle, TreeNode elementTree) {
    super();
    this.tabTitle = tabTitle;
    this.elementTree = elementTree;
}

public TreeNode getElementTree() {
    return elementTree;
}

public void setElementTree(TreeNode elementTree) {
    this.elementTree = elementTree;
}

public String getTabTitle() {
    return tabTitle;
}

public void setTabTitle(String tabTitle) {
    this.tabTitle = tabTitle;
}


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:tabView var="management" value="#{testBean.managements}">
        <p:tab title="#{management.tabTitle}">

            <p:treeTable value="#{management.elementTree}" var="element"
                resizableColumns="true">

                <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:tab>
    </p:tabView>
    <p:commandButton value="#{msg.save}" action="#{testBean.saveAction}" process="@all"
        icon="ui-icon-disk" update="@form" />
</h:form>

我想在TreeNode中处理所有表单值。但是只有第一个选项卡和值在Backing bean中获得。

这是输入:

Frist Tab Second Tab Third Tab

这是输出:

DEBUG: com.smf.web.jsf.bean.TestBean - Company1->Total->1
DEBUG: com.smf.web.jsf.bean.TestBean - Company1->Office->null
DEBUG: com.smf.web.jsf.bean.TestBean - Company2->Total->null
DEBUG: com.smf.web.jsf.bean.TestBean - Company2->Office->null
DEBUG: com.smf.web.jsf.bean.TestBean - Company3->Total->null
DEBUG: com.smf.web.jsf.bean.TestBean - Company3->Office->null

我测试了process =“@ all”和@form ...并且结果相同

我们可以把问题分成两部分:

1.仅处理第一个Tab。  2.只处理树的第一个值。

也许两者的原因是一样的。

让我们开始解析(Values of h:inputText inside p:treeTable are not processed)。

0 个答案:

没有答案