在h:selectOneMenu中选择的值的基础上显示/隐藏h:panelGrid

时间:2014-12-19 07:18:14

标签: jsf primefaces

我想根据<h:panelGrid>中选择的值显示和隐藏<h:selectOneMenu>

代码是:

<p:dialog id="logClassDlg" header="Log Class Teached" widgetVar="logClass" modal="true" >
    <h:form>
        <p:growl id="growl" showDetail="true" />
        <h:panelGrid id="logClassPanelGrd1" columns="2">

            <h:outputLabel for="class" value="Class: " />
            <h:selectOneMenu id="class" value="#{logClassBean.classLog.classTitle}">
                <f:selectItem itemValue="Reading" itemLabel="Reading" />
                <f:selectItem itemValue="Memorization" itemLabel="Memorization" />
                <f:selectItem itemValue="Translation" itemLabel="Translation" />
                <f:selectItem itemValue="Language" itemLabel="Language" />
                <f:selectItem itemValue="Grammer" itemLabel="Grammer" />
                <f:ajax render="logClassPanelGrdBook" />
            </h:selectOneMenu>

        </h:panelGrid>

        <h:panelGrid id="logClassPanelGrdBook" columns="2" rendered="#{(logClassBean.classLog.classTitle ne 'Language') and (logClassBean.classLog.classTitle ne 'Grammar')}">
            <p:outputLabel value="Book" />
            <h:selectOneMenu id="book" value="#{logClassBean.classLog.classStatus}">
                <f:selectItem itemValue="first" itemLabel="first" />
                <f:selectItem itemValue="second" itemLabel="second" />
                <f:selectItem itemValue="third" itemLabel="third" />
                <f:selectItem itemValue="fourth" itemLabel="fourth" />
                <f:selectItem itemValue="fifth" itemLabel="fifth" />
            </h:selectOneMenu>
        </h:panelGrid>

正如您所看到的,我只想在所选值不是语言和语法时显示面板网格logClassPanelGrdBook,即

rendered="#{(logClassBean.classLog.classTitle ne 'Language') and (logClassBean.classLog.classTitle ne 'Grammar')}"

但无论选择的值如何,都会显示面板网格,当选择其他值(读取,记忆和翻译)时,它应隐藏。

任何帮助/指针将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:1)

部分<f:ajax render="logClassPanelGrdBook" />不会以这种方式更新并重新检查panelGrid的渲染函数。您需要更新其父元素。

例如,您可以使用<h:panelGroup>包装它:

        <h:panelGrid id="logClassPanelGrd1" columns="2">

            <h:outputLabel for="class" value="Class: " />
            <h:selectOneMenu id="class" value="#{logClassBean.classLog.classTitle}">
                <f:selectItem itemValue="Reading" itemLabel="Reading" />
                <f:selectItem itemValue="Memorization" itemLabel="Memorization" />
                <f:selectItem itemValue="Translation" itemLabel="Translation" />
                <f:selectItem itemValue="Language" itemLabel="Language" />
                <f:selectItem itemValue="Grammar" itemLabel="Grammar" />
                <f:ajax render="logClassPanelGrdBook" />
            </h:selectOneMenu>

        </h:panelGrid>
        <h:panelGroup id="logClassPanelGrdBook">
        <h:panelGrid columns="2" rendered="#{(logClassBean.classLog.classTitle ne 'Language') and (logClassBean.classLog.classTitle ne 'Grammar')}">
            <p:outputLabel value="Book" />
            <h:selectOneMenu id="book" value="#{logClassBean.classLog.classStatus}">
                <f:selectItem itemValue="first" itemLabel="first" />
                <f:selectItem itemValue="second" itemLabel="second" />
                <f:selectItem itemValue="third" itemLabel="third" />
                <f:selectItem itemValue="fourth" itemLabel="fourth" />
                <f:selectItem itemValue="fifth" itemLabel="fifth" />
            </h:selectOneMenu>
        </h:panelGrid>
        <h:panelGroup>

我还将选择项目值从Grammer更改为Grammar,因为它与渲染属性中的值不匹配。

如果这不起作用,您还应该在单击<h:selectOneMenu>时检查是否正确设置了bean值。