在必填属性和绑定中添加多个条件

问题描述 投票:0回答:1

我想创建一个JSF应用程序。对不起,这个雄心勃勃的要求。在应用程序中,用户将具有三个下拉菜单。

我们可以将多个必需条件添加到一个必需属性中吗?

如果用户从第一个下拉列表中选择国家墨西哥/值3,则需要从多选中选择选项坎昆/值6。>

此外,如果他选择下拉值Continent North America,他还需要从多选中选择Chicago / value 2的选项

我为multiSelectListbox的多个必需选项添加了binding,required属性,但是在选择下拉列表时不会触发它们。>

<h:form>
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true" />

<p:panel header="Tranfer Destination" style="margin-bottom:10px;">
<h:panelGrid columns="2" cellpadding="5">
    <p:outputLabel for="country" value="Country: " />
    <p:selectOneMenu id="country" value="#{dropdownView.country}" style="width:150px" required="true" binding="#{country}">
        <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
        <f:selectItems value="#{dropdownView.countries}" />
        <p:ajax update="city"/
    </p:selectOneMenu>

    <p:outputLabel for="Continent" value="Continent: " />
    <p:multiSelectListbox id="continent" value="#{dropdownView.continent}" style="width:150px" required="true" binding="#{continent}">
        <f:selectItem itemLabel="Select Continent" itemValue="" noSelectionOption="true" />
        <f:selectItem itemLabel="Asia" itemValue="1"> </f:selectItem>
        <f:selectItem itemLabel="Europe" itemValue="2"> </f:selectItem>
        <f:selectItem itemLabel="South America"  itemValue="3"> </f:selectItem>
        <f:selectItem itemLabel="North America" itemValue="4"> </f:selectItem>
        <f:selectItem itemLabel="Africa" itemValue="5"> </f:selectItem>
        <p:ajax update="city"/
    </p:multiSelectListbox>

    <p:outputLabel for="city" value="City: " />
    <p:multiSelectListbox id="city" value="#{dropdownView.city}" style="width:150px" required="#{(not empty param[country.6])  (not empty param[continent.4])}">
        <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
        <f:selectItem itemLabel="New York" itemValue="1"> </f:selectItem>
        <f:selectItem itemLabel="Chicago" itemValue="2"> </f:selectItem>
        <f:selectItem itemLabel="Seattle"  itemValue="3"> </f:selectItem>
        <f:selectItem itemLabel="Toronto" itemValue="4"> </f:selectItem>
        <f:selectItem itemLabel="Ontario" itemValue="5"> </f:selectItem>
        <f:selectItem itemLabel="Cancun" itemValue="6"> </f:selectItem>
        <f:selectItem itemLabel="Tijuana" itemValue="7"> </f:selectItem>
    </p:multiSelectListbox>
 </h:panelGrid>

<p:separator />

<p:commandButton value="Submit" update="msgs" action="#{dropdownView.displayLocation}" icon="pi pi-check" />
</p:panel>
</h:form>

从数据库中填充国家列表

ID NAME

1 USA-C
2 Canada-N
3 Mexico-C

仅当用户从第一个下拉列表中选择国家墨西哥/值3时,才需要从第三个下拉列表中选择Cancun /值6。

仅当用户从第二个下拉列表中选择北美大陆/值4时,才需要从第三个下拉列表中选择芝加哥/值2选项。

其他城市可供选择

我想创建一个JSF应用程序。对不起,这个雄心勃勃的要求。在应用程序中,用户将具有三个下拉菜单。我们可以将多个必需条件添加到一个必需条件中吗?

如果必须这样做,我将不使用required属性,而是创建一个自定义验证器,该验证器检查在第一个和第二个下拉列表中选择的选项,并查看第三个下拉列表是否具有所需的值先前的选择。

jsf primefaces
1个回答
0
投票

如果必须这样做,我将不使用required属性,而是创建一个自定义验证器,该验证器检查在第一个和第二个下拉列表中选择的选项,并查看第三个下拉列表是否具有所需的值先前的选择。

© www.soinside.com 2019 - 2024. All rights reserved.