PDA

View Full Version : Throwaway Controller properties are not bound


vsetal
May 1st, 2005, 12:42 AM
Hi,
I got a really small web project to just let user input information from web form into database, so I think I can get away with ThrowawayController. However, after I tried it out, it seemed that the parameters are not automagically bound to ThrowawayController's properties after submission, as it said in the doc...

Do I have to do anything extra to get the binding work?

Alef Arendsen
May 2nd, 2005, 03:33 AM
Nope, this should just work. Could you show us some more config and the way you're using it?

rgds,
Alef Arendsen

vsetal
May 2nd, 2005, 01:50 PM
Here is the Controller:

public class RegistrationInfo implements ThrowawayController {
private String name;
private Calendar cal = Calendar.getInstance();

public RegistrationInfo() {
super();
name = null;
}

public Date getBirthday() {
return cal.getTime();
}
public void setBirthday(Date birthday) {
this.cal.setTime(birthday);
}
public void setBirthDate(int date) {
cal.set(Calendar.DATE, date);
}
public void setBirthMonth(int month) {
cal.set(Calendar.MONTH, month);
}
public void setBirthYear(int year) {
cal.set(Calendar.YEAR, year);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ModelAndView execute() throws Exception {
return new ModelAndView("indexPage", "result", toString());
}
public String toString() {
return name+":"+getBirthday().toString();
}
}


And here is the config, excluding view configuration stuff

<bean id="throwawayHandler" class="org.springframework.web.servlet.mvc.throwaway.Thro wawayControllerHandlerAdapter"/>
<bean id="simpleHandler" class="org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter"/>

<bean name="/save.html" class="registration.RegistrationInfo" singleton="false"/>


And here is the form for input RegistrationInfo:

<form name="registration" action="save.html" method="post">
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>Birthday:</td>
<td><input type="text" name="birthDate"> / <input type="text" name="birthMonth"> / <input type="text" name="birthYear"></td>
</tr>

marianogo
Dec 26th, 2006, 01:35 PM
I have almost the same problem,

vsetal : what you are missing is getter/setter of the property of cal.

My question is when you have a complex object, You have to declare a propertyEditor? if so, how you declare it.
Suposse a complex object like a

public Class Person{
private String Name;
private String LastName;
//obviously with its setters and getters
}

thanks in advance.