5 Replies Latest reply on Mar 21, 2011 11:56 AM by pschuett

    Usage of h:messages as a replacement of rich:messages

    pschuett

      Hallo,

      during my migration from JSF 1.2 / Richfaces 3.3 to JSF 2.0 / Richfaces 4.0 I try to replace rich:messages.

       

      I have one page on my WEB-GUI and all subpages are included by ui:include (replacement for a4j:include).

      When I got an error in my backing bean code I want to send it to the h:messages control.

       

      Old solution for Richfaces 3.3

       

                  FacesMessage message = new FacesMessage(facesSeverity, shortMsg, longMsg);

                  FacesContext.getCurrentInstance().addMessage(null, message);

       

        <h:form>

           <rich:tabPanel switchType="client">

                 <rich:tab header="tab1" name="tab1">

                       <a4j:outputPanel id="def">

                             <aj4:include viewId="/web/def/index.xhtml"/>

                       </a4j:outputPanel>

                 </rich:tab>

                 <rich:tab header="#{profiling.profiling}" name="profiling" disabled="#{!userDetails.admin}">

                      <a4j:outputPanel id="profiling">

                           <aj4:include viewId="/web/profiling/index.xhtml"/>

                      </a4j:outputPanel>

                 </rich:tab>

             </rich:tabPanel>

             <rich:messages styleClass="top"  layout="list" showDetail="true" style="height:55em; overflow:auto"/>

        </h:form>

       

       

      Now I change the JSF-Code for richfaces 4 to

       

        <h:form>

           <rich:tabPanel switchType="client">

                 <rich:tab header="tab1" name="tab1">

                       <a4j:outputPanel id="def">

                             <ui:include src="/web/def/index.xhtml"/>

                       </a4j:outputPanel>

                 </rich:tab>

                 <rich:tab header="#{profiling.profiling}" name="profiling" disabled="#{!userDetails.admin}">

                      <a4j:outputPanel id="profiling">

                           <ui:include src="/web/profiling/index.xhtml"/>

                      </a4j:outputPanel>

                 </rich:tab>

             </rich:tabPanel>

             <h:messages styleClass="top"  layout="list" showDetail="true" style="height:55em; overflow:auto"/>

        </h:form>

       

       

      and it does not work.

       

      Thanks for any hints.

       

      Ciao

         Peter Schütt

        • 1. Usage of h:messages as a replacement of rich:messages
          ilya40umov

          Try to put h:messages into a4j:outputPanel

          • 2. Usage of h:messages as a replacement of rich:messages
            pschuett

            Hallo,

            I tried

             

            <h:form>

                 <rich:tabPanel switchType="client">

                       <rich:tab header="tab1" name="tab1">

                             <a4j:outputPanel id="def">

                                   <ui:include src="/web/def/index.xhtml"/>

                             </a4j:outputPanel>

                       </rich:tab>

                       <rich:tab header="#{profiling.profiling}" name="profiling" disabled="#{!userDetails.admin}">

                            <a4j:outputPanel id="profiling">

                                 <ui:include src="/web/profiling/index.xhtml"/>

                            </a4j:outputPanel>

                       </rich:tab>

                   </rich:tabPanel>

                    <a4j:outputPanel>

                       <h:messages styleClass="top"  layout="list" showDetail="true" style="height:55em; overflow:auto"/>

                    </a4j:outputPanel>

              </h:form>

             

            but I does not work. Any other hints?

             

            Or do someone has a running example for filling h:messages from a bean?

             

            Ciao

              Peter Schütt

            • 3. Usage of h:messages as a replacement of rich:messages
              ilya_shaikovsky

              richfaces-showcase outputPanel demo contains sample of such usage and it works fine. there are messages added by the component but from action should works the same.. need to re-check wih separate test.

              • 4. Usage of h:messages as a replacement of rich:messages
                pschuett

                Hallo,

                I think I got the problem.

                 

                <?xml version="1.0" encoding="UTF-8"?>

                <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:rich="http://richfaces.org/rich"

                      xmlns:a4j="http://richfaces.org/a4j">

                 

                    <f:view contentType="text/html">

                 

                        <h:head> <title>Sample Page</title></h:head>

                 

                        <h:body>

                            <h1>Sample page</h1>

                 

                            <h:form id="frmAddress">

                 

                                <h:panelGrid columns="1">

                                    <rich:tabPanel switchType="client" >

                                        <rich:tab header="First Tab" >

                <!--                            <a4j:region>

                                                <a4j:outputPanel id="include"> -->

                 

                                                        <a4j:commandButton value="SampleAj4Action"

                                                                           action="#{myBean.doSampleAction}"  execute="@this" immediate="true"/>

                 

                                                        <h:commandButton id="buttonId" value="SampleAction" action="#{myBean.doSampleAction}">

                <!--                                            <a4j:ajax></a4j:ajax> -->

                                                        </h:commandButton>

                 

                <!--                                </a4j:outputPanel>

                                            </a4j:region> -->

                                        </rich:tab>

                                        <rich:tab header="Second Tab" >

                                            Nothing in here!

                                        </rich:tab>

                                    </rich:tabPanel>

                                </h:panelGrid>

                 

                                Here begins Messages: <br />

                                <h:panelGrid>

                 

                                    <h:messages

                                        showDetail="true"

                                        globalOnly="true" showSummary="true" />

                                    <br />

                                </h:panelGrid>

                                End of Messages<br />

                 

                            </h:form>

                 

                 

                        </h:body>

                    </f:view>

                </html>

                 

                 

                    public void doSampleAction()

                    {

                        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,

                                "MySummary", "MyDetail");

                        FacesContext.getCurrentInstance().addMessage(null, message);

                    }

                 

                 

                I think the problem is rich:tab. Without rich:tab both buttons work.

                In a rich:tab the h:commandButton works and the a4j:commandButton does not work.

                If a put the <a4j:ajax> tag into the h:commandButton then the h:commandButton also does not work.

                 

                I try different encapsulations (you see them commented), I try immediate = false, I try execute=@form/@all but

                the a4j:commandButton does not work.

                 

                The same problem I have with rich:fileUpload which is also place in a rich:tab:

                 

                   <rich:fileUpload style="height:100%" fileUploadListener="#{fileUploadBean.uploadListener}"

                                                 maxFilesQuantity="1000"

                                                 id="myUpload" noDuplicate="true"

                                                 immediateUpload="false"

                                                 acceptedTypes="zip" >

                                    <a4j:ajax event="uploadcomplete" execute="@none" render="info, foundDefsTable,importButton" />

                                <f:facet name="label">

                                    <h:outputText value="Import" />

                                </f:facet>

                                </rich:fileUpload>

                 

                The messages I send in uploadcomplete do not reach the h:messages control.

                 

                In the cases where I produce the messages in a button action handler I use as a workaround h:commandButton without

                ajax but for rich:fileUpload I did not find a workaround.

                 

                I think this is a bug but I am not sure. Perhaps you have a solution or a workaround for me.

                 

                Thanks for Your help.

                 

                Ciao

                  Peter Schütt

                • 5. Usage of h:messages as a replacement of rich:messages
                  pschuett

                  Hallo,

                  now in CR-1 is rich:messages available and it is working.

                   

                  Thanks.

                   

                  Ciao

                    Peter Schütt