0 Replies Latest reply on May 10, 2006 11:43 AM by francesco vivoli

    Context variables for JSTL test

    francesco vivoli Newbie

      I've been stuck with this issue for a while now, without understanding if it's supposed to be like this or if I'm doing something wrong.

      I have a dataTable element, that lists questions of a survey. A stripped down version of it follows:

      <h:dataTable var="section" value="#{template.sections}">
       <h:column>
       <h:outputText styleClass="schrift2" value="#{section.title}"/>
       <h:dataTable var="question" value="#{section.questions}">
       <h:column>
       <h:outputText value="#{question.text}"/><br/>
       <c:choose>
       <c:when test="${question.radio}">
       <!-- radio control here -->
       <h:outputText value="RADIO"/>
       </c:when>
       <c:when test="${question.area}">
       <!-- textarea here -->
       <h:outputText value="AREA"/>
       </c:when>
       <c:otherwise>
       <h:outputText value="UNKNOWN TYPE"/>
       </c:otherwise>
       </c:choose>
       </h:column>
       </h:dataTable>
       </h:column>
       </h:dataTable>
      


      I know I could be doing this through a custom component but I decided to try first the simple stuff.

      Basically I instantiate the Questionnaire template in my survey CV as follows

      @Stateful
      @Name("survey")
      @Scope(ScopeType.CONVERSATION)
      @Interceptors(SeamInterceptor.class)
      public class SurveyAction implements Survey {
      
       Logger log = Logger.getLogger(Register.class);
      
       @PersistenceContext (type= PersistenceContextType.EXTENDED)
       private EntityManager em;
      
      
       @Out
       private QuestionnaireTemplate template;
      
       @Create
       public void init() {
       ...
       template = (QuestionnaireTemplate) em.createQuery("from QuestionnaireTemplate t where t.id=1").getSingleResult();
       quest = new Questionnaire(template);
       }
      ...
      


      In the web page I just access the template sections, and for every section I list the related questions. What I'd like to achieve with the above is to have
      "RADIO" printed when the Question has type radio and so on. Right now the type implementation is baselined to

      @Entity
      public class Question implements Serializable {
      ...
       @Transient
       public boolean isRadio(){
       log.info(this+" TYPE "+type);
       return type.equals("single");
       }
      
       @Transient
       public boolean isArea(){
       log.info(this+" TYPE "+type);
       return type.equals("textarea");
       }
      ...
      }
      
      


      When I try to display the table, I always get "UNKNOWN TYPE", and in the logs I see that isRadio() and isOpen() have not been called.
      Nevertheless if I add a method isRadio() to the Survey interface and
      replace the jstl test with

      ...
      <c:when test="${survey.radio}">
       <!-- radio control here -->
       <h:outputText value="RADIO"/>
      </c:when>
      ...
      


      The test is executed correctly.
      Now, I can probably hack something up to get things working, but I wonder if this is just not supposed to be working like this. I mean, is it that I can use a registered CV for jstl tests but not an object used to iterate over a DataModel?

      thanks for any hint on this.
      cheers
      Francesco