5 Replies Latest reply on Nov 14, 2011 8:34 PM by David Sing

    f:paramView on jsf 2  dont' work

    Frederic Papy Newbie

      Good morning,

      I have tree xhtml files in order to show a page:

      the template MasterLayoutaff.xhtml:

      [CODE]

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

      <!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">

            <f:metadata>

                 <f:viewParam name="item" value="#{mysession.id}">

                     <f:event type="preRenderView" listener="#{mysession.preValidateViewParam}" />

                 </f:viewParam>

               </f:metadata>

          <h:head>

         

             <title><ui:insert name="windowTitle"/></title>

                

          </h:head>

         

          <h:body>  

             <div id="header">              

                <ui:insert name="headering">

                   <ui:include src="/composant/header.xhtml"/>

                </ui:insert>

             </div>

             <div id="toolbar">

                <ui:insert name="toolbar">

                   <ui:include src="/composant/toolbar.xhtml"/>

                </ui:insert>

             </div>

            

             <div id="menu">

                <ui:insert name="menu">

                   <ui:include src="/composant/menu1.xhtml"/>

                </ui:insert>

             </div>          

             <div id="content">

                <ui:insert name="content"/>

             </div>   

             <div id="advert">

                <ui:insert name="advert">

                   <ui:include src="/composant/advert.xhtml"/>

                </ui:insert>

             </div>  

             <div id="footer">

                <ui:insert name="footer">

                   <ui:include src="/composant/footer.xhtml"/>

                </ui:insert>

             </div>

                

         </h:body>

      </html>

      [/CODE]

      my page:

      [CODE]

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

      <!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:c="http://java.sun.com/jsp/jstl/core"

            xmlns:ui="http://java.sun.com/jsf/facelets"

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

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

         <h:head>   

          <title>IGNORED</title>      

         </h:head>

         <body >

             <f:view>

                       

                <ui:composition template="./layout/MasterLayoutaff.xhtml">           

                <ui:define name="windowTitle">

                   Ongoladev:#{mysession.curpage}

                </ui:define>

                <ui:define name="content">

                   <ui:include src="groupe.xhtml"/>

                </ui:define>             

             </ui:composition>

             </f:view>      

         </body>

      </html> 

      [/CODE]

      the component groupe:

      [CODE]

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

      <!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>

        

                 <title>IGNORED</title>

         </h:head>

          <body>

             <ui:composition>

             </ui:composition>      

         </body>

      </html>

      [/CODE]

      I dont' have path problems because my page is rendered, but the parameter is not passed and I don't know why.

      So what's the matter?

      Thanks!!

        • 1. Re: f:paramView on jsf 2  dont' work
          Brendan Healey Master

          Hi, I don't think you want the f:event tag nested inside the f:viewParam. The main thing is to

          check if the parameter is actually being passed to the page, is it visible in the browser URL

          on the new page?

           

          I think you need something like this:

           

          <a4j:commandButton action="newPage?faces-redirect=true&amp;includeViewParams=true">

            <f:param ...>

          </a4j:commandButton>

           

          (you don't require faces-redirect=true, but it will update the browser url to the current page, and

          so you should be able to see of the parameter is getting passed...)

           

          I can't honestly remember if I used to use f:param, a4j:param or f:setPropertyActionListener

          nested inside the commandButton.

           

          I can't find an example because I now use the Myfaces CODI @ViewAccessScoped which means

          I don't need to use view parameters any more, which is a relief, because it's a fairly horrible way to

          pass data between pages.

           

          Regards,

          Brendan.

          • 2. Re: f:paramView on jsf 2  dont' work
            Frederic Papy Newbie

            Thanks for your answeer.

            The problem is that I want to came to my page from an other web site. So I can use a an commandButton. Yes my parameter is it visible in the browser URL on the new page. But The bean is not update. So I really don't know what to do.

            • 3. Re: f:paramView on jsf 2  dont' work
              Brendan Healey Master

              Ok, have you moved the f:event outside the f:viewParam tags? what is the data type of mysession.id? what

              data is passed in the url? I was thinking that maybe if it's an int or suchlike you may need a converter

              because the data in the url will be a string. Is there anything in the server logs?

              • 4. Re: f:paramView on jsf 2  dont' work
                David Sing Newbie

                I found the same problem on AS 7.0.1.Final. The problem only occurs when using a jsf template.

                 

                I appears that viewParam isn't executed if the <f:metadata><f:viewParam /></f:metadata> facet is placed in a template.

                 

                I've stopped using templates for the time being.

                • 5. Re: f:paramView on jsf 2  dont' work
                  David Sing Newbie

                  It turns out that <f:viewParam> does work in AS 7.0.1.Final, but you need to go in the <ui:composition> in the target pages, not the template.