Announcement Announcement Module
Collapse
No announcement yet.
Partial rendering of a form with Ajax and fragments Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Partial rendering of a form with Ajax and fragments

    Hi,

    I'm trying to refresh a part of my form with Sring Javascript and tiles fragments: on a select change, I want to populate and refresh another select input.

    It works well when I reload the whole page but when I reload only the second select via Ajax, I have an exception:
    Code:
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'children' available as request attribute
    Here is my code:

    Flow definition
    Code:
    [...]
    <view-state id="form" view="keyword.edit">
      <on-render>
        <evaluate expression="editKeywordAction.setupForm" />
      </on-render>
      <transition on="changeTree">
        <evaluate expression="editKeywordAction.bind" />
        <evaluate expression="editKeywordAction.changeTree" />
        <render fragments="children" />
      </transition>
      <transition on="save" to="finish">
        <evaluate expression="editKeywordAction.bindAndValidate" />
        <evaluate expression="editKeywordAction.save" />
      </transition>
      <transition on="cancel" to="cancel" />
    </view-state>
    [...]

    Tiles definition
    Code:
    <definition name="keyword.edit" template="/jsp/edit.jsp">
      <put-attribute name="children" value="/jsp/children.jsp" />
    </definition>
    JSP
    edit.jsp
    Code:
    <script type="text/javascript">
      function changeTree() {
        $('_eventId').value = 'changeTree';
        Spring.remoting.submitForm('tree', 'keyword', {fragments: 'children'}); 
        return false;
      }
    </script>
    <form:form commandName="keyword" name="keyword" action="${flowExecutionUrl}">
      <input type="hidden" name="_eventId" id="_eventId" value="save" />
      
      <form:select path="tree" id="tree" onchange="changeTree()" multiple="false">
        <form:options items="${trees}" />
      </form:select>
      
      <tiles:insertAttribute name="children" />
    
    </form:form>
    children.jsp
    Code:
    <form:select path="children" id="children" multiple="false">
      <form:options items="${children}" />
    </form:select>
    Exception
    Code:
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'childTest' available as request attribute
      at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:172)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:192)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:158)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:121)
      at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
      at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
      at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
      at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
    Does that means I can only reload the whole form (including the form:form tags) and not only some inputs of this form ?

  • #2
    Hi,
    I'm trying to do exactly the same thing. Did you ever figure out a way of partially rendering the form? I'm guessing it's not possible.

    Comment


    • #3
      No, I did not find a solution for the moment :-(

      Comment


      • #4
        did you find a solution for that problem?

        I have created a jira-issue. see http://jira.springframework.org/browse/SWF-925

        Comment


        • #5
          Yes... I've switched to Wicket ;-)

          Comment


          • #6
            How is this wicket thing... can you work with spring from within wicket?

            Comment


            • #7
              You should be able to use the spring:bind tag around the control you want to re-render partially to setup the same binding in the Ajax case. See the spring:bind tag in the Spring Framework reference manual.

              Keith

              Comment


              • #8
                Does this work in any recent versions?

                As a newbie I am frustrated. Is there a solution for the partial render w/tiles, webflow and bindings? If my spring tags (bind or form) reference a model attribute I get the previously mentioned bind failure. Other attempts such as rendering a simple HTML list not bound to an attribute work fine. I have tried upgrading tiles/spring beyond framework=2.6; webflow=2.08; tiles = 2.06 but only succeeded in breaking tiles on startup. Any guidance is appreciated

                Thanks!

                Comment


                • #9
                  Keith is correct, you can use spring:bind and reference the parent modelAttribute value in the path in order for this to work.

                  Using the Spring form input tags to bind individual properties requires a parent form:form tag in the same fragment (with modelAttribute name) in order for the binding to work when rendering the fragment.

                  Comment


                  • #10
                    I have the same problem. Actually, spring:bind is a solution but it's not convenient. it requires to enclose simple html tags with spring:bind whereas our form is build only with spring form tag. It's complexify the code a make almost useless the use of fragment with form pages.

                    Have you plan to find an easier solution ? Like the idea of https://jira.springframework.org/browse/SWF-1292 to make a tag which do the job of form:form without render an html <form> tag ?

                    Comment


                    • #11
                      any idea if this is resolved?

                      Comment


                      • #12
                        I reload only the second select via Ajax, I have an exception
                        http://www.tara-mediumss.com/male2.jpg
                        http://www.tara-mediumss.com/male3.jpg

                        Comment


                        • #13
                          refreshing a partial form

                          I am new to this forum so forgive me if I am not posting to the proper thread.
                          I know this thread is old but I have not found a solution to this problem anywhere else yet.

                          I have the same problem of refreshing a JSP fragment that's part of a parent
                          JSP (tiles) which declares the form:form. When I receive the refreshed view from the controller,
                          all the paths (in form:input) have been trimmed down a little bit. The initial
                          paths were something like "ticket.selections[0].numbers[0]". The path after the
                          partial refresh were changed to "selections[0].numbers[0]".

                          Is there any standard technique for doing partial form refresh in Spring 3 ?

                          Thanks

                          Comment

                          Working...
                          X