我使用下一页。managedBean的方法可以工作,但不能显示消息:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="/templates/template.xhtml">
<ui:define name="metadata">
</ui:define>
<ui:define name="content">
<h:body>
<h:form id="form">
<p:growl id="msgs1" showDetail="true" />
<!-- <p:outputLabel rendered="#{projectBean.before}" value="registration is not open yet"/>
<p:outputLabel rendered="#{projectBean.after}" value="registration was closed"/>
<p:panel header="#{msg['createProject']}" id="panel" rendered="#{projectBean.checkDate}">-->
<p:panel header="#{msg['createProject']}" id="panel" >
<h:panelGrid columns="3" cellpadding="7" id = "panelGrd">
<h:outputLabel for="name" value="#{msg['name']}*" style="width:100px"/>
<p:inputText id="name" value="#{project.name}" label="#{msg['name']}" style=" padding: 10px; width:400px"
validatorMessage="Name - please input english letters, digits only"
required="true">
<f:validateRegex pattern="^[a-zA-Zsd]+$" />
</p:inputText>
<p:message for="name" display="icon" />
<h:outputText value=" " /><h:outputText value=" " /><h:outputText value=" " />
<h:outputLabel for="meta" value="#{msg['meta']}*" />
<p:inputText id="meta" value="#{project.meta}" label="#{msg['meta']}" style=" padding: 10px; width:400px"
validatorMessage="Meta - please input english letters, digits only"
required="true">
<f:validateRegex pattern="^[a-zA-Zsd]+$" />
</p:inputText>
<p:message for="meta" display="icon" />
<h:outputText value=" " /><h:outputText value=" " /><h:outputText value=" " />
<h:outputLabel for="des" value="#{msg['description']}*" />
<p:inputTextarea rows="5" cols="30" id="des" counter="display" maxlength="250"
counterTemplate="{0} #{msg['charactersRemaining']}." value="#{project.description}"
label="#{msg['description']}" autoResize="false" style=" padding: 10px; width:400px "
validatorMessage="Description - please input english letters, digits only"
required="true">
<f:validateRegex pattern="^[a-zA-Zsd]+$" />
</p:inputTextarea>
<p:message for="des" display="icon" />
<h:outputText value=" " /><h:outputText id="display" /><h:outputText value=" " />
<h:outputText value=" " /><h:outputText value=" " /><h:outputText value=" " />
<h:outputLabel for="amount2" value="#{msg['sphere']}" />
<p:selectOneMenu id="amount2" value="#{project.sphere}" label="#{msg['sphere']}" style="width:400px">
<f:selectItems value="#{enumValuesProvider.spheres}"
var="sphere"
itemValue="#{sphere}"
itemLabel="#{sphere.name}"/>
</p:selectOneMenu>
<h:outputText value=" " />
<h:outputText value=" " /><h:outputText value=" " /><h:outputText value=" " />
<h:outputLabel for="pattern" value="#{msg['manager']}*" />
<p:inputText id="pattern" value="#{project.manager}" label="#{msg['manager']}" style=" padding: 10px; width:400px"
validatorMessage="Manager - please input english letters, digits only"
required="true">
<f:validateRegex pattern="^[a-zA-Zsd]+$" />
</p:inputText>
<p:message for="pattern" display="icon" />
<h:outputText value=" " /><h:outputText value=" " /><h:outputText value=" " />
<h:outputLabel for="checked" value="#{msg['team']}" />
<p:inputText id="checked" value="#{project.team}" style=" padding: 10px; width:400px"
validatorMessage="Team - please input english letters, digits only" >
<f:validateRegex pattern="^[a-zA-Zsd]+$" />
</p:inputText>
<p:message for="checked" display="icon" />
<h:outputText value=" " /><h:outputText value=" " /><h:outputText value=" " />
<h:outputText value=" " />
<p:commandButton value="#{msg['save']}" ajax="false" icon="ui-icon-check" validateClient="true"
actionListener="#{projectBean.addProject}" style="left: 312px;" >
</p:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</ui:define>
方法:
public void addProject(){
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "You voting is saved", "Thank you for you chose");
RequestContext.getCurrentInstance().showMessageInDialog(message);
}
我认为问题是在panel或panelGrid。但另一方面,方法从这个位置起作用。有人能帮我解决这个问题吗
我找到原因了。它是- ajax="false"。我删除它,并显示消息