commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sweetland, Jesse" <JSweetl...@talk.com>
Subject RE: [betwixt] Bean to Bean mapping
Date Mon, 09 Oct 2006 17:21:13 GMT
Betwixt only converts value-for-value.  If you need to break the date out
like that then you need to create a new element bean:

public class MyClass {
	private Date _myDate = new Date();

	public Date getMyDate() {
		return _myDate;
	}

	public DateBean getMyDateBean() {
		return new DateBean(_myDate);
	}
}

public class DateBean {
	private Calendar _calendar = Calendar.getInstance();
	
	public int getDay() {
		return _calendar.get(Calendar.DATE);
	}

	public int getMonth() {
		return _calendar.get(Calendar.MONTH + 1);
	}

	public int getYear() {
		return _calendar.get(Calendar.YEAR);
	}

	public DateBean(Date date) {
		_calendar.setTime(date);
	}
}

Then map that bean using a DateBean.betwixt file.  You can also add setters
for round-tripping.

Hope that helps,

Jesse

-----Original Message-----
From: Peter Konstantinov [mailto:pa@iu6.ru] 
Sent: Monday, October 09, 2006 12:11 PM
To: commons-user@jakarta.apache.org
Subject: [betwixt] Bean to Bean mapping

Hi,
How to convert java.util.Date to same xml:
<date day="..." month="..." year="..." />
ConvertUtilsObjectStringConverter can convert only to String.

Regards,
Peter

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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message