You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Sloots <pe...@xs4all.nl> on 2004/01/22 15:27:01 UTC

Converting data in a ActionForm

Hi

I'm using the following code in a ActionForm to convert 3 strings to a Timestamp, 
problem is that some of the string are null, getBirthdateMonth() is still null because setBirthdateMonth() 
is called after setBirthdate(). Can someone tell me what is the right approach.

I would like to handle all the dataconversion in the form class. 
Now I'm calling setBirthdate() from the Action class, to make this work.
But I don't see a way to get the values from the form before the setBirthdateMonth is called.

What is a best practice to do this kind of dataconversion.


	public String getBirthdate() {
		Date birthdate = null;
		Timestamp ts = this.data.getBirthdate();
		if (ts != null) {
			birthdate = new Date(ts.getTime());
			setBirthdateDay(formatDay.format(birthdate));
			setBirthdateMonth(formatMonth.format(birthdate));
			setBirthdateYear(formatYear.format(birthdate));
			return ts.toString();
		}
		return null;
	}

	public void setBirthdate(String birthdate) {
		Date date = formatBack.parse(getBirthdateYear() + "-" + getBirthdateMonth() + "-" + getBirthdateDay(), new java.text.ParsePosition(0));
		Timestamp ts = null;
		if (date != null) {
			ts = new Timestamp(date.getTime());
			this.data.setBirthdate(ts);
		}
	}





---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org