tags:

views:

50

answers:

1

I'm working on a project which I need to generate a form dynamically. The user chooses the component he wants to put on the screen and the program adds it in the form. To do so, I'm using XML to define the current state of the form and at first sight I thought in using XSLT to make the transformation to JSF but now I am evaluating JSTL too. Regarding the last one, I have a problem.

Suppose I have this xml file (a questionnaire with two inputTexts):

<questionnaire>
    <component name='input'>
        <id>input1</id>
    </component>
    <component name='input'>
        <id>input2</id>
    </component>
</questionnaire>

And this JSTL file:

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<x:parse var="doc" xml="${questionarioXSLBean.xml}"/>

<x:forEach var="n" select="$doc/questionario/componente">
 <x:if select="$n/@nome = 'input'">
  <x:set var="id" select="$n/id" />
  <h:inputText id="#{id}"/>
 </x:if>
</x:forEach>

The problem is in this line: <h:inputText id="#{id}"/> 'cause #{id} doesn't return anything (I want to use the value that is in xml file and assigned in id variable).

Can anyone help me? Thanks in advance! P.S.

A: 

JSF, on the other hand, has a much more complex life cycle. Somewhat simplified, JSF components are created, asked to process their input (if any), and then asked to render themselves. For JSF to work well, these three things must happen separately in a well-defined order, but when JSF is used with JSP, they don't. Instead, the component creation and rendering happens in parallel, causing all kinds of problems. The fact that both JSP and JSF components add content to the response is another cause for a lot of grief. Unless you understand the difference between how these two technologies write to the response, you're in for a lot of surprises, such as content appearing out of order or not at all. --As discussed here

Thus, using JSF and JSP together will give you unpredictable results. You are better off taking a pure JSF approach using XSLT as mentioned above

Gaurav Saxena
Thanks Gaurav. Regarding XSLT, I had a problem using it and I couldn't find a solution to it. Maybe you can help me somehow. The problem is that after the transformation the component tags generated always include a namespace definition inside it, this way JSF can't recognize the component codification. For instance, instead of generate <h:inputText id="input1"/> it generates <h:inputText id="input1" xmlns:h="http://java.sun.com/jsf/html"/>. Is there any way of suppressing it?
Paulo S.
This would require a look at the tool / code you are using to generate JSF. Can't think anything from the top of my head
Gaurav Saxena