0

我有两个复选框。

<h:panelGrid id="userActivationGridcheckbox">
    <p:selectManyCheckbox value="#{user.activationModecheckbox}" layout="pageDirection">
        <f:selectItem itemLabel="Account Expiration(in days)" itemValue="byEmailcheckbox" />  
        <f:selectItem itemLabel="Reset User Password" itemValue="byAdmincheckbox" />  
        <f:ajax event="change" render="userActivationGridcheckbox" /> 
    </p:selectManyCheckbox>

    <h:panelGrid id="manualActivationGridcheckbox" rendered="#{user.manualActivationcheckbox}" columns="2">
        <p:selectOneRadio value="#{user.activationModecheckbox}" layout="pageDirection">
            <f:selectItem itemLabel="label1" itemValue="value1" />
            <f:selectItem itemLabel="label2" itemValue="value2" />
            <h:outputLabel>label</h:outputLabel>
            <h:inputText value="" />
        </p:selectOneRadio>
    </h:panelGrid>
</h:panelGrid>

当第一个复选框被选中时,应该会出现另外 2 个单选按钮。如果未选中第二个复选框,则不应显示单选按钮。我怎样才能做到这一点?

4

2 回答 2

0

您需要在某些侦听器方法中决定是否向用户显示无线电组,例如,通过在支持 bean 中保留一个布尔值。然后只需通过 AJAX 渲染组件。

示例用法:

风景:

<h:form>
    <p:selectManyCheckbox id="check" value="#{bean.options}">
        <p:ajax process="@this" update="radio" listener="#{bean.listener}" />
        <f:selectItem itemLabel="Option 1" itemValue="Option 1" />
        <f:selectItem itemLabel="Option 2" itemValue="Option 2" />
    </p:selectManyCheckbox>
    <h:panelGroup id="radio" layout="block">
        <h:panelGrid rendered="#{bean.needsSuboptions}" columns="2">
            <p:selectOneRadio value="#{bean.suboption1}" layout="pageDirection" >
                <f:selectItem itemLabel="Select ---" itemValue="" />
                <f:selectItem itemLabel="Suboption 1-1" itemValue="Suboption 1-1" />
                <f:selectItem itemLabel="Suboption 1-2" itemValue="Suboption 1-2" />
            </p:selectOneRadio>
            <p:selectOneRadio value="#{bean.suboption2}" layout="pageDirection" >
                <f:selectItem itemLabel="Select ---" itemValue="" />
                <f:selectItem itemLabel="Suboption 2-1" itemValue="Suboption 2-1" />
                <f:selectItem itemLabel="Suboption 2-2" itemValue="Suboption 2-2" />
            </p:selectOneRadio>
        </h:panelGrid>
    </h:panelGroup>
</h:form>

还有豆子:

List<String> options;//getter+setter
String suboption1;//getter+setter
String suboption2;//getter+setter
boolean needsSuboptions = false;//getter

public void listener() {
    needsSuboptions = options.contains("Option 1");
}
于 2013-05-22T11:09:52.023 回答
0

您也可以使用 f:ajax 作为 skuntsel 提供的代码。

<f:ajax render="" execute="" listener=""/>

映射到:

<p:ajax update="" process="" listener=""/>


<p:selectManyCheckbox id="check" value="#{displayPanel.options}">
            <f:ajax event="change" render="radio" listener="#{displayPanel.listener}" />
            <f:selectItem itemLabel="Option 1" itemValue="Option 1" />
            <f:selectItem itemLabel="Option 2" itemValue="Option 2" />
        </p:selectManyCheckbox>
        <h:panelGroup id="radio" layout="block">
            <h:panelGrid rendered="#{displayPanel.n}" columns="2">
                <p:selectOneRadio value="#{displayPanel.a}" layout="pageDirection">
                    <f:selectItem itemLabel="Select ---" itemValue="" />
                    <f:selectItem itemLabel="Suboption 1-1" itemValue="Suboption 1-1" />
                    <f:selectItem itemLabel="Suboption 1-2" itemValue="Suboption 1-2" />
                </p:selectOneRadio>
                <p:selectOneRadio value="#{displayPanel.b}" layout="pageDirection">
                    <f:selectItem itemLabel="Select ---" itemValue="" />
                    <f:selectItem itemLabel="Suboption 2-1" itemValue="Suboption 2-1" />
                    <f:selectItem itemLabel="Suboption 2-2" itemValue="Suboption 2-2" />
                </p:selectOneRadio>
            </h:panelGrid>

您忘记了 f:ajax 的提供侦听器。

于 2013-05-22T12:48:42.397 回答