3 Replies Latest reply on Sep 17, 2008 5:52 PM by bashan

    Evaluate facelets parameter in java

    bashan

      Hi,


      I am having a problem evaluating facelets parameter in Java code.
      I have this simple component:




      <span xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:s="http://jboss.com/products/seam/taglib"
            xmlns:t="http://myfaces.apache.org/tomahawk"
            xmlns:c="http://java.sun.com/jsp/jstl/core"
            xmlns:a4j="http://richfaces.org/a4j">
      
        #{test}
        #{someBean.test}
        </span>





      I am calling it:





      <s:testcomp test="4" />






      The output in the page is: 4.


      the function test in the bean looks like:
         



      Object value = Expressions.instance().createValueExpression("#{test}").getValue();






      The value in the java code is always null.
      How can I evaluate facelets parameter?

        • 1. Re: Evaluate facelets parameter in java
          bashan

          Does anyone know about this problem? Any idea for a workaround?

          • 2. Re: Evaluate facelets parameter in java
            sjmenden

            The test variable will live in a different VariableMapper (in the FaceletContext) than what you are evaluating which occurs in the FacesContext.  So you have 2 options:



            1. Access #{test} inside of a Facelet TagHandler

            2. Create a TagHandler which sets the test variable in the FacesContext




            I don't quite understand what:



             #{someBean.test}



            does consider it would evaluate for example to personBean.get4() ? since your test="4".  You could always do something like:


            #{someBean.someMethod(test)}



            which would pass that value to someMethod.




            • 3. Re: Evaluate facelets parameter in java
              bashan

              I used this:


               #{someBean.test}



              just as a dummy to activate the test method and being able to examine the EL expression in Java code.
              Actually I am trying to get the facelets parameter in a getter of a value passed to a dataTable, therefore, I won't be able to send a parameter (your suggestion).


              The truth is, I took the time to get rid of all the java code and did all the work in XHTML file in order to workaround this problem.


              But question still remains and is very simple:
              How can a facelets parameter can be extracted in Java code (using EL)?


              Thanks.