Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Partial rendering of a form with Ajax and fragments

  1. #1

    Default 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. #2
    Join Date
    Sep 2007
    Location
    London
    Posts
    12

    Default

    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.

  3. #3

    Default

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

  4. #4
    Join Date
    Jul 2007
    Location
    Frankfurt am Main, Germany
    Posts
    15

    Default

    did you find a solution for that problem?

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

  5. #5

    Default

    Yes... I've switched to Wicket ;-)

  6. #6
    Join Date
    Jul 2008
    Location
    Medellín, Colombia
    Posts
    135

    Default

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

  7. #7
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    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
    Keith Donald
    Core Spring Development Team

  8. #8
    Join Date
    Jan 2010
    Posts
    1

    Question 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!

  9. #9
    Join Date
    May 2010
    Posts
    1

    Default

    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.

  10. #10
    Join Date
    Aug 2010
    Posts
    6

    Default

    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 ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •