4 Replies Latest reply on Nov 24, 2010 12:23 PM by Alexandr Areshchanka

    Passing bean instance as param to a facelet

    jrachev Newbie

      Hello,


      I have this problem. In a facelet composition I have declare some links that should certain action from a bean, which bean I want to specify from another facelet which uses the composition. Here is my code.
      The Composition paging.xhtml:



      ....
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:s="http://jboss.com/products/seam/taglib"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html">
              <table>
              <tr>
                      <td align="center">
                              <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                      <h:graphicImage value="/img/FirstPage.gif" rendered="#{bean.getPage()!=0}" />
                      <h:graphicImage value="/img/FirstPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                              </s:link>
                  <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                      <h:graphicImage value="/img/PreviousPage.gif" rendered="#{bean.getPage()!=0}" />
                      <h:graphicImage value="/img/PreviousPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                  </s:link>
                  <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                      <h:graphicImage value="/img/NextPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                      <h:graphicImage value="/img/NextPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                  </s:link>
                  <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                      <h:graphicImage value="/img/LastPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                      <h:graphicImage value="/img/LastPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                  </s:link>
               </td>
           </tr>
      </table>
      </ui:composition>
      .....


      and the client page client.xhtml





      .....
          <table>
              <tr><td align="center">
                      <ui:include src="/layout/paging.xhtml">
                              <ui:param name="bean" value="#{NewElectronicStatementsAction}" />
                      </ui:include>
              </td></tr>
          </table>
      .....

      It is strange because when there are no more pages the relevant links becomes disabled and and the images do change, but when I any of the links(which are not disabled of course) an exception rises:




      Exception during request processing:
      Caused by javax.el.PropertyNotFoundException with message: Target Unreachable, identifier 'bean' resolved to null

      So why comes that my code works for the state of the links, but does not for the action invocation? And how should I fix it?
      Thanks in advance.



        • 1. Re: Passing bean instance as param to a facelet
          jrachev Newbie

          Jakim Rachev wrote on Nov 19, 2010 11:44:


          Hello,

          I have this problem. In a facelet composition I have declare some links that should certain action from a bean, which bean I want to specify from another facelet which uses the composition. Here is my code.
          The Composition paging.xhtml:



          ....
          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html">
                  <table>
                  <tr>
                          <td align="center">
                                  <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                          <h:graphicImage value="/img/FirstPage.gif" rendered="#{bean.getPage()!=0}" />
                          <h:graphicImage value="/img/FirstPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                                  </s:link>
                      <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                          <h:graphicImage value="/img/PreviousPage.gif" rendered="#{bean.getPage()!=0}" />
                          <h:graphicImage value="/img/PreviousPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                      </s:link>
                      <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                          <h:graphicImage value="/img/NextPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                          <h:graphicImage value="/img/NextPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                      </s:link>
                      <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                          <h:graphicImage value="/img/LastPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                          <h:graphicImage value="/img/LastPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                      </s:link>
                   </td>
               </tr>
          </table>
          </ui:composition>
          .....




          and the client page client.xhtml

          ....
              <table>
                  <tr><td align="center">
                          <ui:include src="/layout/paging.xhtml">
                                  <ui:param name="bean" value="#{NewElectronicStatementsAction}" />
                          </ui:include>
                  </td></tr>
              </table>
          .....





          It is strange because when there are no more pages the relevant links becomes disabled and and the images do change, but when I any of the links(which are not disabled of course) an exception rises:


          Exception during request processing:
          Caused by javax.el.PropertyNotFoundException with message: Target Unreachable, identifier 'bean' resolved to null


          So why comes that my code works for the state of the links, but does not for the action invocation? And how should I fix it?
          Thanks in advance.





          Click HELP for text formatting instructions. Then edit this text and check the preview.

          • 2. Re: Passing bean instance as param to a facelet
            jrachev Newbie

            Jakim Rachev wrote on Nov 19, 2010 11:47:



            Jakim Rachev wrote on Nov 19, 2010 11:44:


            Hello,

            I have this problem. In a facelet composition I have declare some links that should certain action from a bean, which bean I want to specify from another facelet which uses the composition. Here is my code.
            The Composition paging.xhtml:



            ....
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:s="http://jboss.com/products/seam/taglib"
                  xmlns:ui="http://java.sun.com/jsf/facelets"
                  xmlns:h="http://java.sun.com/jsf/html">
                    <table>
                    <tr>
                            <td align="center">
                                    <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                            <h:graphicImage value="/img/FirstPage.gif" rendered="#{bean.getPage()!=0}" />
                            <h:graphicImage value="/img/FirstPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                                    </s:link>
                        <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                            <h:graphicImage value="/img/PreviousPage.gif" rendered="#{bean.getPage()!=0}" />
                            <h:graphicImage value="/img/PreviousPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                        </s:link>
                        <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                            <h:graphicImage value="/img/NextPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                            <h:graphicImage value="/img/NextPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                        </s:link>
                        <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                            <h:graphicImage value="/img/LastPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                            <h:graphicImage value="/img/LastPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                        </s:link>
                     </td>
                 </tr>
            </table>
            </ui:composition>
            .....




            and the client page client.xhtml

            ....
                <table>
                    <tr><td align="center">
                            <ui:include src="/layout/paging.xhtml">
                                    <ui:param name="bean" value="#{NewElectronicStatementsAction}" />
                            </ui:include>
                    </td></tr>
                </table>
            .....





            It is strange because when there are no more pages the relevant links becomes disabled and and the images do change, but when I any of the links(which are not disabled of course) an exception rises:

            Exception during request processing:
            Caused by javax.el.PropertyNotFoundException with message: Target Unreachable, identifier 'bean' resolved to null


            So why comes that my code works for the state of the links, but does not for the action invocation? And how should I fix it?
            Thanks in advance.





            Click HELP for text formatting instructions. Then edit this text and check the preview.


            Click HELP for text formatting instructions. Then edit this text and check the preview.

            • 3. Re: Passing bean instance as param to a facelet
              jrachev Newbie

              Hello,


              I have this problem. In a facelet composition I have declare some links that should certain action from a bean, which bean I want to specify from another facelet which uses the composition. Here is my code.
              The Composition paging.xhtml:




              ....
              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:s="http://jboss.com/products/seam/taglib"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:h="http://java.sun.com/jsf/html">
                      <table>
                      <tr>
                              <td align="center">
                                      <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                              <h:graphicImage value="/img/FirstPage.gif" rendered="#{bean.getPage()!=0}" />
                              <h:graphicImage value="/img/FirstPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                                      </s:link>
                          <s:link action="#{bean.getPage()}" disabled="#{bean.getPage()==0}">
                              <h:graphicImage value="/img/PreviousPage.gif" rendered="#{bean.getPage()!=0}" />
                              <h:graphicImage value="/img/PreviousPage_Disabled.gif" rendered="#{bean.getPage()==0}" />
                          </s:link>
                          <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                              <h:graphicImage value="/img/NextPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                              <h:graphicImage value="/img/NextPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                          </s:link>
                          <s:link action="#{bean.isNextPageAvailable()}" disabled="#{!bean.isNextPageAvailable()}">
                              <h:graphicImage value="/img/LastPage.gif" rendered="#{bean.isNextPageAvailable()}" />
                              <h:graphicImage value="/img/LastPage_Disabled.gif" rendered="#{!bean.isNextPageAvailable()}" />
                          </s:link>
                       </td>
                   </tr>
              </table>
              </ui:composition>
              .....




              and the client page client.xhtml


              ....
                  <table>
                      <tr><td align="center">
                              <ui:include src="/layout/paging.xhtml">
                                      <ui:param name="bean" value="#{NewElectronicStatementsAction}" />
                              </ui:include>
                      </td></tr>
                  </table>
              .....





              It is strange because when there are no more pages the relevant links becomes disabled and and the images do change, but when I any of the links(which are not disabled of course) an exception rises:





              Exception during request processing:
              Caused by javax.el.PropertyNotFoundException with message: Target Unreachable, identifier 'bean' resolved to null







              So why comes that my code works for the state of the links, but does not for the action invocation? And how should I fix it?
              Thanks in advance.

              • 4. Re: Passing bean instance as param to a facelet
                Alexandr Areshchanka Newbie

                What scope is your bean? Try to use page, conversation, session.