1

在form2中提交命令按钮后,我想更新form1中的selectOneMenu。它现在仅在刷新页面后可见。

我在表格 1 中有一个 selectOneMenu:

<h:form id="form1" rendered="#">

            <p:spacer height="30" />
            <h:selectOneMenu id="oneMenu" value="#{bean.value}">
                <f:selectItem itemLabel="Select Value" itemValue="" />
                <f:selectItems id="itemValues"
                    value="#{bean.allItems}" var="allItems"
                    itemValue="#{allItems}" itemLabel="#{allItems.name}" />
            </h:selectOneMenu>

和 form2 中的 DialogBOX:

<h:form id="form2">
            <p:dialog header="Create new Item" widgetVar="newItem"
                resizable="false">

                <h:panelGrid columns="2" style="margin-bottom:10px">

                    <h:outputLabel for="item" value="Itemname:" />
                    <p:inputText id="itemname" value="#{bean.itemName}" />
                </h:panelGrid>

                <p:commandButton value="Submit"
                    actionListener="#{bean.newItem}"
                    update="form1:oneMenu" oncomplete="newItem.hide();"  />

            </p:dialog>

我试过update="form1:oneMenu"了,但它不起作用。我也读过这篇文章 ,但它也不起作用。

感谢帮助。

4

1 回答 1

1

确保使用update=":form1:myPanel".

例子 :

<h:form id="form1">
    <h:selectOneMenu id="oneMenu" value="#{bean.value}">
    ...
    </h:selectOneMenu>
</h:form>

<h:form id="form2">
    <p:dialog ..>
        ...
        <p:commandButton value="Submit" update=":form1:oneMenu" ..../>
    </p:dialog>
</h:form>

否则

<h:form id="form1">
    <p:selectOneMenu id="oneMenu" value="#{bean.value}">
    ...
    </p:selectOneMenu>
</h:form>

<h:form id="form2">
    <p:dialog ..>
        ...
        <p:commandButton value="Submit" update=":form1:oneMenu" ..../>
    </p:dialog>
</h:form>

更新评论:试试下面。您可以使用h:selectOneMenup:selectOneMenu

<h:form id="form1">
    <p:selectOneMenu style="width:195px;" required="true" id="cityMenu">
        <f:selectItems value="#{SelectOneMenuBean.cities}"/>
    </p:selectOneMenu>
    <p:commandButton oncomplete="newItem.show()" value="Show Dialog"/>
</h:form>
<h:form id="form2">
    <p:dialog header="Create new Item" widgetVar="newItem" resizable="false">
        <h:panelGrid columns="2" style="margin-bottom:10px">
            <h:outputLabel for="item" value="Itemname:" />
            <p:inputText id="itemname" value="#{SelectOneMenuBean.selectedValue}" />
        </h:panelGrid>

        <p:commandButton value="Submit" update=":form1:cityMenu" oncomplete="newItem.hide();"  />

    </p:dialog>     
</h:form>

public class SelectOneMenuBean {
    private String selectedValue;

    public String getSelectedValue() {
        return selectedValue;
    }

    public void setSelectedValue(String selectedValue) {
        this.selectedValue = selectedValue;
    }

    public String[] getCities() {
        if(selectedValue != null && selectedValue.equals("AAA")) {
            return new String[] {"City_1 of AAA", "City_2 of AAA", "City_3 of AAA"};
        } else if(selectedValue != null && selectedValue.equals("BBB")) {
            return new String[] {"City_1 of BBB", "City_2 of BBB", "City_3 of BBB"};
        } else if(selectedValue != null && selectedValue.equals("CCC")) {
            return new String[] {"City_1 of CCC", "City_2 of CCC", "City_3 of CCC"};
        } else if(selectedValue != null && selectedValue.equals("DDD")) {
            return new String[] {"City_1 of DDD", "City_2 of DDD", "City_3 of DDD"};
        } 
        return new String[] {"No City"};
    }
}

注意:如果您在对话框中输入 value AAA、和BBB,的值将被更改。CCCDDDselectedOneMenu

于 2012-11-15T10:54:26.493 回答