SourceForge.net Logo
Version: 0.27 - Last update: 2004-05-30 Home Page - SourceForge Project Page - Contact

Jodd
  Overview
  News
  Download
  License
  References

Development
  Using Jodd
  Javadoc
  JUnit report

Community
  Contribute
  Report a bug

More reading
  Milestone 0.30



Top 25%

BSD
 

Forms

Jodd provides a solution for form handling in an very easy way. There is no high-level automatism, everything is at the very same level as the basic Servlets. Jodd introduces few utilities which significantly may help for retrieving posted data from a form as well as populating form.

Loading form beans

Thanks to the jodd.bean.BeanUtil class, form beans can be very simply loaded from the request:

form beans
 
FooFormBean ffb = new FooFormBean();		// create form bean (or get it)
BeanUtil.load(ffb, request);			// load form bean from request
...
HttpSession session = request.getSession();
session.setAttribute("bean", ffb);		// send it further

And that is all. The only thing developer needs to take care off is to name html input fields equally to names of form bean properties. Hint: form beans do not have to be instanced on each request as in above example. Instead, instance can be obtained from some scope etc.

Populate forms with magic

Form beans that are stored in scopes may be used for populating html forms. And it really looks like magic: create form in plain HTML and surround it by a Jodd's form tag. And that is all!

html form
 

<form name="sony" method="post" action="ReadForm">
<jodd:form beans="bean" scopes="session">

<input type="checkbox" name="Foocheck1">

<input type="text" name="Footext">

<select name="Fooselect">
	<option value="option1">option #1</option>
	<option value="option2">option #2</option>
	<option value="option3">option #3</option>
</select>

</jodd:form>
</form>


Jodd's form tag will get all form beans specified in the tag from various source, i.e. scopes. From beans are simple Java beans, which property names must match form's input names.

One form may be populated from more than one bean and in this case bean names and their scopes must be comma separated.

Working example can be found in the Jodd distribution.


http://jodd.sourceforge.net
najgor at users.sourceforge.net