Jsf 选择SelectOne菜单上的项目时显示表单

Jsf 选择SelectOne菜单上的项目时显示表单,jsf,primefaces,Jsf,Primefaces,我正在开发J2EEWeb应用程序(jsf2和primefaces),我想知道如何根据从“选择一个”菜单中选择的项目显示表单。 我试过了,但没用 <h:form id="global"> <p:panel header="Association"> ... <p:outputLabel value="Travel Class" /> <p:selectOneMenu id="associationT

我正在开发J2EEWeb应用程序(jsf2和primefaces),我想知道如何根据从“选择一个”菜单中选择的项目显示表单。 我试过了,但没用

<h:form id="global">
   <p:panel  header="Association">
         ...
     <p:outputLabel  value="Travel Class" />     
     <p:selectOneMenu id="associationType" style="width: 230px" value="#{associationMBean.travelClass}">
                                            <f:selectItem itemLabel="Select one" itemValue="" />  
                                            <f:selectItem itemLabel="Seminar" itemValue="Seminar" />   
                                            <f:selectItem itemLabel="Honeymoon" itemValue="Honeymoon" /> 
                                            <f:selectItem itemLabel="Organized Trip" itemValue="Organized Trip" />
                                            <p:ajax update=":hidePanel"/> 
                                        </p:selectOneMenu>     
   </p:panel>
</h:form>
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)"  rendered="#{associationMBean.travelClass eq Seminar}"> 
<h:form>            
<p:inputTextarea style="width: 100% ; height: 100px" value="#{associationMBean.description}" ></p:inputTextarea> 
</h:form>              
</p:panel>

...
更新

<html 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Visa Application-Thailand</title>

    </h:head>
    <h:body>
        <div align="center">
            <div>
                <img class="logo" src="images/banner.jpg"/>
            </div>
            <p:panel style="width: 61%;  border-color: indianred; border-width: 2px; margin-top: 10px"> 
                <h:form id="global">
                    <p:panel style="margin-top: 20px; font-size: 14px ; border: 0" header="Association">
                        <table border="0" >
                            <tbody > 
                                <tr>
                                    <td align="right">
                                        <p:outputLabel  value="Association Type" />
                                    </td >
                                    <td align="left">
                                        <p:selectOneMenu id="selectmenu" style="width: 230px" value="#{associationMBean.type}">
                                            <f:selectItem itemLabel="Select a Class" itemValue="" />  
                                            <f:selectItem itemLabel="Seminar" itemValue="Seminar" />
                                            <f:selectItem itemLabel="Organized Trip" itemValue="Organized Trip" />
                                            <f:selectItem itemLabel="Honeymoon" itemValue="Honeymoon" />
                                            <p:ajax update=":hidePanel"/>
                                        </p:selectOneMenu>   

                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">
                                        <p:outputLabel value="Date of Departure" for="departure" />
                                    </td>
                                    <td align="left">
                                        <p:calendar  value="#{associationMBean.departure}" showOn="button" pattern="dd/MM/yy" style="width: 250px" id="departure"></p:calendar>
                                        <p:watermark value="01/01/2014" for="departure"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <p:outputLabel value="Date of Arrival" for="arrival" />
                                    </td>
                                    <td align="left">
                                        <p:calendar  value="#{associationMBean.arrival}" showOn="button" pattern="dd/MM/yy" style="width: 250px" id="arrival"></p:calendar>
                                        <p:watermark value="01/01/2014" for="arrival"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <p:outputLabel  value="Travel Agency " for="travelAgency"/>
                                    </td>
                                    <td align="left">
                                        <p:inputText id="travelAgency" value="#{associationMBean.travelAgency}" style="width: 220px"></p:inputText>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <p:outputLabel  value="Airline " for="airline"/>
                                    </td>
                                    <td align="left">
                                        <p:inputText id="airline" value="#{associationMBean.airline}" style="width: 220px"></p:inputText>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <p:outputLabel  value="Travel Class" />
                                    </td >
                                    <td align="left">        
                                        <p:selectOneMenu id="selectclass" style="width: 230px" value="#{associationMBean.travelClass}">
                                            <f:selectItem itemLabel="Select a Class" itemValue="" />  
                                            <f:selectItems value="#{associationMBean.allClasses}" />
                                            <!--  <p:ajax update=":hidePanel"/> !-->
                                        </p:selectOneMenu>                                   
                                    </td>
                                </tr> 

                                <tr >
                                    <td align="right">
                                        <p:outputLabel  value="Hotels " for="hotels" />
                                    </td>
                                    <td align="left">
                                        <p:inputTextarea id="hotels" value="#{associationMBean.hotels}" style="width: 220px"/>
                                    </td>
                                </tr>               
                            </tbody>
                        </table>
                    </p:panel>
                    <div align="right" style="margin-top: 20px ">
                        <p:commandButton type="reset" value="Reset" style="font-size: 14px;"/>
                        <p:commandButton value="Save"  ajax="false" styleClass="ui-priority-primary" style="font-size: 14px;" action="#{associationMBean.addAssociation()}" />
                    </div>
                </h:form>            
                <p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)" >
                    <h:form rendered="#{associationMBean.type == 'Seminar'}" >
                        <p:inputTextarea style="width: 100% ; height: 100px" value="#{visaMBean.description}" ></p:inputTextarea>
                    </h:form>
                </p:panel>         
            </p:panel>
        </div>
    </h:body>
</html>

泰国签证申请
上面的代码是添加了一些更新后的全部html代码,但是当我从SelectOne菜单中选择Seminar时,仍然无法显示hidePane。
你知道我遗漏了什么吗?

以下方法应该有效:

<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)"> 
  <h:form rendered="#{associationMBean.travelClass eq 'Seminar'}">
    <p:inputTextarea style="width: 100% ; height: 100px" value="#{associationMBean.description}" ></p:inputTextarea> 
  </h:form>              
</p:panel>

不能更新不在DOM中的组件,并且当未渲染组件时,该组件不在DOM中。因此,需要更新条件渲染组件的父级。
由于
{associationMBean.travelClass}
是一个字符串,您需要用单引号将
'Seminar'
括起来
'

尝试用输出面板包围hidePanel并更新此输出面板。当我选择Seminar nothing时,同样的问题就是解决方案,原因是面板不存在于html页面中,因为呈现的属性被计算为false,ajax请求只能更新html页面中存在的dom元素