3 Replies Latest reply on Aug 10, 2015 9:42 AM by askkuber

    How to Show Notification Message in Richfaces PopUP Panel ?

    askkuber

      What is my Problem ?

      For me error/information/notification message working fine for all Non Popup JSF pages but in case of Popup, message showing is not working.


      I have design the JSF page like this


      <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"
         xmlns:fn="http://java.sun.com/jsp/jstl/functions">
      
      <ui:composition template="../templates/home-template.xhtml">
         <ui:define name="content">
         <h:form id="id">
        ..........
        ..........
        ..........
        ..........
         </h:form>
         <ui:define/>
      
      </ui:composition>
      
      

      home-template.xhtml design is something like this


      <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"
         xmlns:c="http://java.sun.com/jsp/jstl/core">
      
        <h:outputScript name="jquery.js" target="head"/>
        <h:outputScript name="someother.js" target="head"/>
        <h:head>
        <link rel="stylesheet" type="text/css" href="../resources/css/style.css" />
        <h:body>
        <head>
        ...........
        ...........
        </h:head>
        <h:form>
        ..........
        ..........
        ..........
        </h:form>
       <div class="body-main">
      
         <div>
         <rich:panel id="messagePanel">
         <ui:include src="../templates/message/Error.xhtml"/>
         <ui:include src="../templates/message/Success.xhtml"/>
         <ui:include src="../templates/message/NotifyWarning.xhtml"> 
         </rich:panel>
         </div>
      </h:body>
      
      </html>
      
      

      In Error.xhtml i have written below code


      <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:f="http://java.sun.com/jsf/core"
         xmlns:a4j="http://richfaces.org/a4j"
         xmlns:rich="http://richfaces.org/rich">
         <rich:notify id="flashErrorMessage1" rendered="#{flash.errorMessage.length() > 0 }"  
        showShadow="false" sticky="true">
         <f:facet name="detail">
         <rich:panel id="flashErrorMessage"  >
         <h:graphicImage value="../resources/image/error.png" />
      
        Failed:#{messages.errorMessage}
      
         </rich:panel>
         </f:facet>
         </rich:notify>
      </ui:composition>
      
      

       

      In Bean class i am doing like this


      Flash messages = FacesContext.getCurrentInstance().getExternalContext()
         .getFlash();
      messages .put("errorMessage", bundle
         .getString("failedupdate"));
      
      

       

      This is working fine for normal pages(NON POPUP Pages).

       

      What i tried ?

      But now for popup pages its not working even in popup window i tried to add

      <h:messages styleClass="errorMessage" globalOnly="true" />
      
      

       

      but it wont work.

       

      Then i added below code in popup window and it worked fine

      <h:outputText value="Add Group Feature" rendered="#{flash.errorMessage.length() > 0 }"/>
      

       

      How i am calling Popup Window?

      From normal JSF Pages through command button i am calling Popup Window.

       

      <ui:composition template="../templates/home-template.xhtml">
       <ui:define name="content">
         <ui:include src="popup.xhtml" >
         <ui:param name="parentBean" value="#{BeanName}" />
         </ui:include>
         <h:form id="id">
        ..........
        ..........
        ..........
         <a4j:commandButton value="PopUpWindow" action="#{BeanName.someAction}" oncomplete="#{rich:component('popup')}.show(true)" ></a4j:commandButton>
         </h:form>
         <ui:define/>
      
      </ui:composition>
      
      

       

      From PopUp Window JSF Bean I am calling Parent JSF Bean method

       

      Flash flash = FacesContext.getCurrentInstance().getExternalContext()
         .getFlash();
      
      
      public String addFeature(Object parentBeanName){
         if(parentBeanName instanceof A){
        A a = (A) parentBeanName;
        a.addFeature(featuesObj,flash);
         }else if(parentBeanName instanceof B){
        B b  = (B) parentBeanName;
        b.addFeature(featuesObj,flash);
         } 
         return null;
         
      }
      
      

       

      And addFeature() method which is inside ParentBean of Popup

      public String addFeature(MyFeature feature,Flash flashObj) {
       if(Some condtion){
      flashObj.put("errorMessage",feature.getName()+ bundle.getString("message"));
      return null;
      }
      
      }