Solution for Spring 3.0.x
If you see error like this: "Neither BindingResult nor plain target object for bean name ... available as request attribute " and you get mad , then instead of punch innocent display ... try to chill out, drink beer and look to your code more carefully,because above error mean that have "a little" bit mess in your form(model) java file or jsp file
Probably:
1) in form(model) file:
a)you have not implement setters , getters or both
b) they are named wrongly(misspelled?) (so spring couldn't find it)
package xxx.losers.epicfail.forms.FailForm;
public class FailForm {
String name;
String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
2) in your jsp file
in your form, path attribute is misspell or doesn't exist in form
<form:form name=" failform" method="POST" commandName=" failform " action="uploadfailform.html"> <fieldset>
<legend>Upload Image</legend>
<p>
<form:input path="name" />
<form:input path="description" />
</p>
</fieldset>
</form:form>
<form:form action="/securedArea" commandName="uploadItem" enctype="multipart/form-data"></form:form>
3)Check is your element is between <form> </form>
<form:form name=" failform" method="POST" commandName=" failform " action="uploadfailform.html"> <fieldset>
<legend>Upload Image</legend>
<p>
<form:input path="name" />
<form:input path="description" />
</p>
</fieldset>
</form:form>
4)
In your controller you added @ModelAttribute(" failform ") FailForm failform add failform to model
public String create(HttpSession session, @ModelAttribute(" failform ") FailForm failform , BindingResult result, Model model) {
(...)
model.addAttribute("failform ", failform );
return "fail/epic";
5 and more?) Probably other reasons exist,but i didn't come across ... yet.
DOMINIK SYMONOWICZ's blogs - FOREVER HUNGRY of knowledge, sarcasm, smiling, music, dancing, and food ...lots of food. This IT blog is a collection of notes with a simple solution with an explanation, added documentation, sarcastic comment and weird example. I also write about a lesson learnt from my mistakes. A non-it blog can be found here: Dominik Symonowicz's non-IT blog and website
Showing posts with label form. Show all posts
Showing posts with label form. Show all posts
19 April 2011
8 April 2011
how to implement two submit using one form in html
If you have amazing form but you want 2 (or more) submission with different action ..then you thinking... that is a problem,because you define action in form,so a. what you should do ?
<!-- (...) your marvelous form -->
</form>
draft example:
<form method="POST" name="diary" action="save.html">
<!-- put all form rubbish stuff .... like this 3 lines below. -->
Title <input type="text" id="newseditor"/><br/>
Note<input type="textarea" id="newseditor"/><br/>
Is is true story<input type="checkbox" id="newseditor"/><br/>
<!-- here is important place when you set multiple submit stuff with diffrent actions -->
<input type="submit" value="Save" onclick="diary.action='save.html'; return true;">
<input type="submit" value="Load" onclick="diary.action='load.html'; return true;">
</form>
- First create you outstanding form
<!-- (...) your marvelous form -->
</form>
- SecondlyAdd normal submit button, but add onclick with line that will set action depend on submission
- For each next submit only what you need to change is action (onclick="diary.action=nameofaction;return true;" for submit button (and name that will be display and other unique setting for you submit button)
draft example:
<form method="POST" name="diary" action="save.html">
<!-- put all form rubbish stuff .... like this 3 lines below. -->
Title <input type="text" id="newseditor"/><br/>
Note<input type="textarea" id="newseditor"/><br/>
Is is true story<input type="checkbox" id="newseditor"/><br/>
<!-- here is important place when you set multiple submit stuff with diffrent actions -->
<input type="submit" value="Save" onclick="diary.action='save.html'; return true;">
<input type="submit" value="Load" onclick="diary.action='load.html'; return true;">
</form>
Subscribe to:
Posts (Atom)