我在p:accordionpanel的选项卡中有一个表单,所以每个选项卡都有自己的表单和命令按钮。命令按钮工作正常,但是不显示p:消息。如果验证失败,数据不存储在数据库中,我只是没有得到消息。
支持bean是会话作用域。
模板中没有表单,因此没有表单嵌套在另一个表单中。我曾尝试在命令按钮中添加f:ajax render="messages",正如BalusC在他的11个问题中建议的那样,询问命令按钮是否失败,但随后命令按钮不再工作。
谢谢你的帮助!
<ui:define name="content">
<p:accordionPanel value="#{activityAdminController.activities}" var="a" activeIndex="#{activityAdminController.activeTab}">
<p:ajax event="tabChange" listener="#{activityAdminController.onTabChange}" />
<p:tab title="#{a.description}">
<h:form id="activityForm">
<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
<p:panelGrid styleClass="activityGrid">
<p:row>
<p:column><h:outputLabel for="activity" value="Activity: " /></p:column>
<p:column>
<p:inputText id="activity" value="#{a.description}" required="true" requiredMessage="Activity name must be entered" />
</p:column>
<p:column>
<h:outputLabel for="duration" value="Duration: " />
</p:column>
<p:column>
<p:inputText id="duration" value="#{a.duration}" >
<f:validateLongRange minimum="1" />
</p:inputText>
</p:column>
</p:row>
<p:row>
<p:column><h:outputLabel for="active" value="Active: " /></p:column>
<p:column><p:selectBooleanCheckbox id="active" value="#{a.isActive}" /></p:column>
</p:row>
<p:row>
<p:column><h:outputLabel value="Monday from: " /> </p:column>
<p:column> <p:calendar value="#{a.day2FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column><h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day2ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
</p:row>
<p:row>
<p:column> <h:outputLabel value="Tuesday from: " /> </p:column>
<p:column> <p:calendar value="#{a.day3FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column><h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day3ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
</p:row>
<p:row>
<p:column><h:outputLabel value="Wednesday from: " /> </p:column>
<p:column><p:calendar value="#{a.day4FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column><h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day4ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
</p:row>
<p:row>
<p:column><h:outputLabel value="Thursday from: " /> </p:column>
<p:column> <p:calendar value="#{a.day5FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column> <h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day5ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
</p:row>
<p:row>
<p:column><h:outputLabel value="Friday from: " /> </p:column>
<p:column> <p:calendar value="#{a.day6FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column><h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day6ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
</p:row>
<p:row>
<p:column><h:outputLabel value="Saturday from: " /> </p:column>
<p:column> <p:calendar value="#{a.day7FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column><h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day7ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /></p:column>
</p:row>
<p:row>
<p:column><h:outputLabel value="Sunday from: " /> </p:column>
<p:column><p:calendar value="#{a.day1FromTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
<p:column><h:outputLabel value="to: " /> </p:column>
<p:column><p:calendar value="#{a.day1ToTime}" pattern="HH:mm" timeOnly="true" minHour="8" maxHour="22" stepMinute="30" /> </p:column>
</p:row>
</p:panelGrid>
<p:commandButton value="Save" action="#{activityAdminController.submit()}" icon="ui-icon-check" process="@form" />
</h:form>
</p:tab>
</p:accordionPanel>
</ui:define>
在p:commandButton中添加update="@parent"解决了这个问题。
感谢BalusC关于update属性的提示。
我使用的是PrimeFaces 3.4.2