带有primefaces的动态页面内容

时间:2013-07-02 07:15:38

标签: java ajax primefaces javabeans

我正在创建一个网页。内容应根据用户选择而变化。

我需要2个单选按钮,可以选择一天和多天(开始日期和结束日期),如果一天所选页面应该显示一个日历以选择日期,否则两个日历选择开始日期和结束日期我尝试过使用ajax渲染的propety但我无法查看日历我怎么能这样做

我的xhtml

<h:form id="f1">
                    <p:growl id="createmsg"/>  
                    <h:panelGrid columns="2" cellpadding="10">
                        <p:panel id="add_visitor_details_pnl" style="width:100%"> 
                            <h:panelGrid id="grid" columns="2" cellpadding="10">
                                <h:outputText value="Organization :" />
                                <p:selectOneMenu  editable="true" value="#{visitorBean.organization}"  style="width:160px"  filter="true" filterMatchMode="startsWith">
                                    <f:selectItems value="#{visitorBean.organizations}" />
                                </p:selectOneMenu>
                                <h:outputText value="Visitor Name :" />
                                <p:selectOneMenu value="#{visitorBean.name}"  style="width:160px"  filter="true" filterMatchMode="startsWith">
                                    <f:selectItems value="#{visitorBean.names}" />
                                </p:selectOneMenu>
                                <h:outputText value="Visitor ID :" />
                                <p:selectOneMenu value="#{visitorBean.id}"  style="width:160px"  filter="true" filterMatchMode="startsWith">
                                    <f:selectItems value="#{visitorBean.ids}" />
                                </p:selectOneMenu>                                                         
                                <h:outputText value="Purpose :" />
                                <p:inputTextarea id="purpose_it" value="#{visitorBean.purpose}" required="true" autoResize="false"
                                             requiredMessage="Enter Purpose" rows="10" cols="50"/>
                            </h:panelGrid>
                            <h:panelGrid columns="1" cellpadding="10">
                                <p:selectOneRadio id="customRadio" value="#{visitorBean.option}" >  
                                    <f:selectItem itemLabel="Create a one day appointment" itemValue="1" />  
                                    <f:selectItem itemLabel="create a day period appointment" itemValue="2" />
                                    <p:ajax event="change" listener="#{visitorBean.selectDayType()}" 
                                            update=":f1:add_visitor_details_pnl"     />
                                </p:selectOneRadio>
                            </h:panelGrid>
                            <h:panelGrid id="date" columns="3" cellpadding="10">
                                <h:outputText id="date1" value="Date" rendered="#{visitorBean.cal1}"/> 
                                <p:calendar id="calender_Cal1" value="#{visitorBean.date_time}" 
                                            pattern="yyyy-MM-dd"  rendered="#{visitorBean.cal1}" 
                                            required="true" requiredMessage="Enter Date Time"/>
                                <p:calendar id="calender_Cal2" value="#{visitorBean.date_time}" 
                                            pattern="yyyy-MM-dd"  rendered="#{visitorBean.cal2}" 
                                            required="true" requiredMessage="Enter Date Time"/>
                            </h:panelGrid>
                            <h:panelGrid columns="2" cellpadding="10">
                                <p:commandButton id="submit_visitor_Btn" value="Create"                                                         
                                                 action="#{visitorBean.submitVisitorData()}"
                                                 update=":f1:visitor_dataTable,:f1:grid,:f1:createmsg"/>



                            </h:panelGrid> 

我的ajax方法

public void selectDayType(){
    if(option =="1")
        cal1 = "true";
    else if(option =="2"){
        cal1="true";
        cal2="true";            
    }

1 个答案:

答案 0 :(得分:0)

尝试使用:

围绕日历
<p:outputPanel  id="someId" >
...
</p:outputPanel>

Primefaces - Output Panel