Announcement Announcement Module
Collapse
No announcement yet.
component id problem after rendering a fragment by sf/ajax Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • component id problem after rendering a fragment by sf/ajax

    Hello everybody,

    I develop a web apllication with the following technologies:
    - Spring 2.5.6 + Spring Webflow 2.0.6
    => Ajax by dojo 1.2
    - JSF: Apache MyFaces 1.2.3
    - Facelets 1.1.14

    Problem description:
    I have a page (xhtml) with a form and different input components inside.
    Amongst others I iterate a list by <c:forEach> to generate dynamic
    <h:inputText> components. I set the component ids by myself.

    Example:
    <ui:fragment id="content">
    <c:forEach items="#{propertyList}" var="property">
    <h:inputText id="#{property.id}" value="#{property.text}" />
    </c:forEach}
    </ui:fragment>

    The rendered result looks like:
    <input type="text" id="1" value="Text A for the component with id 1" />
    <input type="text" id="2" value="Text B for the component with id 2" />
    (o.k.)

    Now I send an ajax request by an sf-Tag, e.g. <sf:commandLink> and tell
    the webflow only to render the fragment "content"
    => a dojo.xhr-Request will be sent to the server (o.k.)
    On the server a third property will be inserted by my business service in the
    list at postion 0, so that the propertyList contains the three properties
    property 3, property 1, property 2.
    When the ajax response is received and the fragment is rendered it looks fine
    in the browser, but in the source code of the page the component ids look
    like this:
    <input type="text" id="1" value="Text C for the component with id 3" />
    <input type="text" id="2" value="Text A for the component with id 1" />
    <input type="text" id="2" value="Text B for the component with id 2" />

    So the id's at position 1 + 2 are not updated and the id at position 3
    equals the id at position 2. => it's duplicate...

    Perhaps it's a problem that the jsf modell hasn't updated after rendering
    the fragment by ajax???


    I'm grateful, if anybody has a solution for this problem...

  • #2
    Just out of curiousity, do you see the same behavior if you change your ui:fragment to an h: panelGrid?

    Comment


    • #3
      Hello InverseFalcon,

      thank you for your answer, but I don't understand how I could render
      only components inside <h: panelGrid> by an ajax response in combination
      with Spring Webflow/ Spring Faces instead of <ui:fragment> ?
      <h: panelGrid> will be rendered as <table> - Tag and <ui:fragment> is a
      peace of facelet which can be used by Spring Webflow to render only
      the components inside instead of the whole site...

      Comment


      • #4
        Recall that ui:fragment shouldn't render anything special either. Like you said, it's all just HTML, once it gets to the client. The ids used in the render fragments tag work with ids of components in the JSF component tree server side, and are then used to rerender the markup. Thus the ids used in your render fragments tag should be valid ids on JSF components (doesn't work with ids on HTML elements, as far as I can tell). The fact that the render fragments tag has "fragments" in the name has nothing to do with the "ui:fragment" facelet tag.

        Comment


        • #5
          Hello InverseFalcon,

          I didn't know that I can rerender every view element (and not only <ui:fragment>) by using fragments-Tag in webflow. So I've tested the behaviour with <hanelGrid>, but 'it's always the same problem...

          I think there must be a solution to insert view components in the jsf componentmodel by an ajax request?!

          Comment


          • #6
            Huh. Don't know what to tell you, here. I would have expected this to work.

            Just double checking, but what is the output if you use this:

            Code:
            <h:inputText id="#{property.id}" value="#{property.id} - #{property.text}" />

            Also, as a potential workaround, you can can try the Facelets ui:repeat tag.

            Comment


            • #7
              fixed by using &lt;h: panelGrid&gt;

              Hello InverseFalcon,

              at first the answer to your question about output:
              <input type="text" id="1" value="3 - Text C for the component with id 3" />
              <input type="text" id="2" value="1 - Text A for the component with id 1" />
              <input type="text" id="2" value="2 - Text B for the component with id 2" />

              But now I fixed my problem by surrounding my <c: forEach> with <h: panelGrid>, so you were right. Last time I told you that it doesn't work, because I made an other error myself, sorry. But my application is more complex than this example, so I'm using dojo dnd inside and I don't have only some text input components. There are also a lot of nested <div>- Tags and some other input components like text area and so on.

              Thanks a lot! Now I can go on holiday!

              Comment

              Working...
              X