根据h:selectOneRadio值有条件地启用/禁用p:selectManyMenu

时间:2014-10-16 07:43:47

标签: jsf primefaces toggle selectoneradio selectmanymenu

我有2个单选按钮,一个启用和禁用。如果我单击启用,则应禁用所有selectmanymenu标签,反之亦然。请你帮助我好吗。我已附上以下代码。

单选按钮代码:

<div>
    <h:selectOneRadio value="#{userData.data}" layout="pageDirection" id="filterGroup"
     required="true"  styleClass="control-group searchFilterRow searchFilterFont floatL" >
        <f:selectItem itemValue="1" itemLabel="By Part" />
        <f:selectItem itemValue="0" itemLabel="By Filter" />
    </h:selectOneRadio>
    </div> 

    <div class="floatL filterSection">
    <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"
            columnClasses="label, value">

            <p:outputLabel styleClass="disblock" for="display11" value="Vehicle Programs:" />
            <div class="controls">
                <p:selectManyMenu id="display11"
                    value="#{selectManyView.selectedThemes}" converter="themeConverter"
                    var="t" filter="true" filterMatchMode="contains"
                    showCheckbox="true" styleClass="selectManyContainer"  disabled="#{(userData.data==1)}" >
                    <f:selectItems value="#{selectManyView.themes}" var="theme"
                        itemLabel="#{theme.displayName}" itemValue="#{theme}" />

                    <p:column>
                        <h:outputText styleClass="ui-theme ui-theme-#{t.name}" />
                    </p:column>

                    <p:column>
                        <h:outputText value="#{t.displayName}" />
                    </p:column>
                </p:selectManyMenu>
            </div>
        </h:panelGrid>
</div>
        <div class="floatL  filterSection">
        <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"
            columnClasses="label, value">


            <p:outputLabel for="advanced" value="CSS:" />
            <div class="controls">
                <p:selectManyMenu id="advanced"
                    value="#{selectManyView.selectedThemes}" converter="themeConverter1"
                    var="t" filter="true" filterMatchMode="contains"
                    showCheckbox="true" styleClass="selectManyContainer" disabled="#{(userData.data==1)}"  >
                    <f:selectItems value="#{selectManyView.themes}" var="theme"
                        itemLabel="#{theme.displayName}" itemValue="#{theme}"  />

                    <p:column>
                        <h:outputText styleClass="ui-theme ui-theme-#{t.name}" />
                    </p:column>

                    <p:column>
                        <h:outputText value="#{t.displayName}" />
                    </p:column>
                </p:selectManyMenu>
            </div>
        </h:panelGrid>

        <p:separator />

        </div>

Bean代码:

package radioButton;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "userData", eager = true)
@SessionScoped

    public class UserData implements Serializable {

        private static final long serialVersionUID = 1L;

        public String data = "1";

        public String getData() {
            return data;
        }

        public void setData(String data) {
            this.data = data;
        }
    }

1 个答案:

答案 0 :(得分:0)

您需要在selectOneRadio中添加ajax组件以刷新selectManyMenu的组件。

<h:selectOneRadio value="#{userData.data}" layout="pageDirection" id="filterGroup"
 required="true"  styleClass="control-group searchFilterRow searchFilterFont floatL" >
    <f:selectItem itemValue="1" itemLabel="By Part" />
    <f:selectItem itemValue="0" itemLabel="By Filter" />
    <f:ajax render="display11 advanced"/> //id's of the selectManyMenu's
</h:selectOneRadio>

如果您打算切换到<p:ajax update="display11 advanced"/>组件,请使用<p:selectOneRadio>