0

I am using tiles, Spring MVC, Spring form tag. I want to make a form that step by step. When click a button, show more inputs from another tiles definition. But throw a exception can not find "Neither BindingResult nor plain target object for bean name " , It looks the "more inputs" can not get bindle object from previous request, is it right?

Source code:

<form:form action="/saveTicker.do" commandName="ticker" modelAttribute="ticker" method="post">
 ...
 <form:input path="name" id="name"/>
 <a href="#" class="btn" onclick="confirmTicker();">Confirm</a>
<div class="row" id="filelist">
</div>
</form>

js

var confirmTicker=function(){
var ticker=$('input:text').val();
$.get("/confirmTicker.do",{ticker:ticker}).success(function(data){
    $('#filelist').html(data);
});

}

want to import another file

<table class="table ">
<c:forEach var="f" items="${fileList}">
    <tr>
        <td>
            <form:checkbox path="files" value="${f}"></form:checkbox>
        </td>
    </tr>
</c:forEach>
</table>

The error is

Neither BindingResult nor plain target object for bean name 'files' available as request attribute
BenMorel
  • 34,448
  • 50
  • 182
  • 322
atu0830
  • 405
  • 7
  • 15
  • Can you post the controller method code as well? – Dangling Piyush Feb 18 '13 at 05:07
  • Use commandName or modelAttribute; Not both. And Did you add 'ticker' in the model. [**Check my answer HERE**](http://stackoverflow.com/questions/8781558/neither-bindingresult-nor-plain-target-object-for-bean-name-available-as-request/8785223#8785223). Might help. – Vinay Feb 18 '13 at 09:11

1 Answers1

0

If I am reading this correct, what you want is a "wizard" form where the user is passed from one form to the next as a series of steps. First, I believe Spring Web Flow does this out of the box, but, if like me, you cannot use Spring Web Flow you can do this manually.

First, you need a Form Bean (read Command object) that has all the possible inputs from all the forms.

Next, you will either have one Controller method that accepts your Form Bean and returns the proper step (this is what I did), or you can have multiple methods...it doesn't matter. You will use the @ModelAttribute annotation on the handler method to bind the Form Bean to the view form. Also, @SessionAttributes annotation at the top of the controller to set the Form Bean as a session attribute. Make sure the name of the @ModelAttribute, @SessionAttribute, and the view all correspond to the same attribute name.

Last, create multiple views, each with the same , but each with only the pieces you want to set on the FormBean at that point. You cannot use JSR 303, or at least I don't know how you can, since you can't have validation done between steps. You will have to handle validation at the end on your own.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • It looks a little hard, just found a simple solution, use jquery load a new form to instead of old form. – atu0830 Mar 16 '13 at 01:52