jsf 2 - Global messages not displaying in <rich:messages> -
i have jsf 2.1 + richfaces 4.0 webapp on jboss eap 6.0. not able display custom error messages bean user using facesmessage. adding message using addmessage(). however, message not show in <rich:messages> , in console getting:
info [javax.enterprise.resource.webcontainer.jsf.renderkit] (http-localhost/127.0.0.1:8888-3) warning: facesmessage(s) have been enqueued, may not have been displayed. sourceid=null[severity=(error 2), summary=(mobile no should greater 10 degits), detail=()].
view:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <ui:composition> <h:head/> <link href="../../css/styles.css" rel="stylesheet" type="text/css" /> <h:form id="personform12" > <h:panelgrid id="test2343" width="80%"> <rich:messages id="messages" globalonly="true" errorclass="globalerror" showsummary="true" showdetail="false"></rich:messages> </h:panelgrid> <h:panelgrid border="0" columns="3" width="90%" cellpadding="0" cellspacing="1" > <h:panelgroup styleclass="alignmentright"> <h:outputtext value="#{bundle['id']}" /> </h:panelgroup> <h:inputtext id="id" value="#{personbean.pdto.id}" required="true"> </h:inputtext> <rich:message styleclass="error" for="id" /> <h:panelgroup> <h:outputtext value="#{bundle['name']}" /> </h:panelgroup> <h:inputtext id="name" value="#{personbean.pdto.name}" required="true"/> <rich:message styleclass="error" for="name" /> <h:panelgroup styleclass="alignmentright"> <h:outputtext value="city" /> </h:panelgroup> <h:inputtext id="city" value="#{personbean.pdto.city}" required="true"/> <rich:message styleclass="error" for="city" /> <h:panelgroup styleclass="alignmentright"> <h:outputtext value="state" /> </h:panelgroup> <h:inputtext id="state" value="#{personbean.pdto.state}" required="true"/> <rich:message styleclass="error" for="state" /> <h:panelgroup styleclass="alignmentright"> <h:outputtext value="mobile" /> </h:panelgroup> <h:inputtext id="mobile" value="#{personbean.pdto.mobile}" required="true"> </h:inputtext> <rich:message styleclass="error" for="mobile" /> <h:panelgroup styleclass="alignmentright"> <h:outputtext value="dob" /> </h:panelgroup> <rich:calendar style="height:25px" inputstyle="width:203px" required="true" showweeksbar="false" boundarydatesmode="scroll" id="dob" value="#{personbean.pdto.dob}" datepattern="dd/mm/yyyy" cellwidth="24px" cellheight="22px" /> <rich:message styleclass="error" for="dob" /> </h:panelgrid> <br/><br/> <h:commandbutton id="commandsubmit" value="submit" action="#{personbean.save}"></h:commandbutton> </h:form> </ui:composition> </html> model:
public class personjsfbean { private static final logger log = logger.getlogger(personjsfbean.class); private persondto pdto; private personmanager personmanager; public string save(){ string str = null; try { if(pdto.getmobile().length()<10) { system.out.println("inside mobile no>>>>>>>>>>>"+pdto.getmobile()); facesmessage facesmsg = new facesmessage(facesmessage.severity_error, "mobile no should greater 10 degits ", null); facescontext.getcurrentinstance().addmessage(null, facesmsg); } } catch (exception e) { system.out.println("error occured>>>>>>>>>>>"); e.printstacktrace(); } return str; } // ... }
as there no template attribute in ui:composition assume page top level one. h:body missing, here example:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <h:head/> <h:body> <h:form ..... </h:body> </html>
Comments
Post a Comment