2 Replies Latest reply on Apr 28, 2006 11:32 AM by Gavin King

    Dynamically generate form elements

    francesco vivoli Newbie


      probably this is not a strictly Seam related question, but here it is...

      Displaying a form i need to display the proper input type (textarea, checkbox,radio etcetc) based on the type of the element.
      One possibility I see is to use for example jstl tags to create an if-else sequence. Given that the possible types are limited and fixed this doesn't
      seem to be a problem.
      Nevertheless it doesn't appeal me much, so I'd like to hear your opininon about this...

      Another possibility could be having a method like getFormElement(Type)
      that would add the element through


      But doing this I loose readability of the page code, providing a flexibility that probably is not needed...

      Any hint?


        • 1. Re: Dynamically generate form elements
          francesco vivoli Newbie

          Ok, I have been trying the jstl way...

          Nevertheless I have been running into the following problem:

          In my jsp I have

          <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
           <h:dataTable var="question" value="#{section.questions}">
           <h:outputText value="#{question.text}"/><br>
           <c:when test="${question.radio}">
           <h:selectOneRadio value="#{register.selection[question]}" required="true"
           <f:selectItems value="#{question.answerTypes}"/>
           <h:outputText value="#{question.type}"/>

          and actually question.isRadio() returns true.
          The problem is that it always takes the otherwise branch. I don't really understand what's the problem, it's almost the same that the dvd example does (same libraries as well).

          Can it be of me using jsps instead of facelets? Is it supposed to matter anyway?

          Thanks for any hint on this!

          • 2. Re: Dynamically generate form elements
            Gavin King Master

            Mixing JSTL with JSF in JSP usually does not work very well. Seriously consider using facelets instead.

            BTW, this might be a good case for a JSF custom component.