struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petzsch, Martin" <martin.petz...@capgemini.com>
Subject @ConversionErrorFieldValidator and Collections
Date Mon, 06 Aug 2007 14:06:11 GMT

Hi,

I have a data bean which contains a date field. I annotate the set method
with:
	@ConversionErrorFieldValidator(message="aDate: Conversion Error")
	@RequiredFieldValidator(message="aDate: Required Field")
	public void setADate(Date date) {
		aDate = date;
	}

This works find and I get the messages in the expected order depending on my
input.

The same data bean also contains a List of another data bean and the
associated methods:
	private List<InnerBean> innerList;
	@VisitorFieldValidator(message="Inner Message:",appendPrefix=false)
	public List<InnerBean> getInnerList() {
		if (innerList == null) {
			innerList = new ArrayList<InnerBean>();
			innerList.add(new InnerBean());
		}
		return innerList;
	}

	public void setInnerList(List<InnerBean> innerList) {
		this.innerList = innerList;
	}

My inner bean is as follows:
	private Date innerProp;
	public Date getInnerProp(){
		return innerProp;
	}
	
	@ConversionErrorFieldValidator(message="innerProp: Conversion
Error")
	@RequiredFieldValidator(message="innerProp: Required Field")
	public void setInnerProp(Date str){
		innerProp = str;
	}

The required field validator works as expected.  I do not however get any
result EVER back from the ConversionErrorFieldValidator on the inner bean.
If I enter an incorrect value it simply does not get set.

Does anyone have a working example of ConversionErrorFieldValidator inside a
bean which is inside a collection?

Many thanks,
Martin


Source Code Follows
===============================================
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import
com.opensymphony.xwork2.validator.annotations.ConversionErrorFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator;

public class MyDataBean {
	private Date aDate;
	private List<InnerBean> innerList;	
	
	public MyDataBean() {
	}

	@VisitorFieldValidator(message="Inner Message",appendPrefix=false)
	public List<InnerBean> getInnerList() {
		if (innerList == null) {
			innerList = new ArrayList<InnerBean>();
			innerList.add(new InnerBean());
		}
		return innerList;
	}

	public void setInnerList(List<InnerBean> innerList) {
		this.innerList = innerList;
	}

	public Date getADate() {
		return aDate;
	}

	// this works fine
	@ConversionErrorFieldValidator(message="aDate: Conversion Error")
	@RequiredFieldValidator(message="aDate: Required Field")
	public void setADate(Date date) {
		aDate = date;
	}
}
--------
/**
 * 
 */
import java.util.Date;

import
com.opensymphony.xwork2.validator.annotations.ConversionErrorFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;

/**
 * @author MPETZSCH
 *
 */
public class InnerBean {
	private Date innerProp;
	
	public Date getInnerProp(){
		return innerProp;
	}
	
	// this does not work
	@ConversionErrorFieldValidator(message="innerProp: Conversion
Error")
	@RequiredFieldValidator(message="innerProp: Required Field")
	public void setInnerProp(Date str){
		innerProp = str;
	}
}


Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini
UK plc, a company registered in England and Wales (number 943935) whose registered office
is at No. 1 Forge End, Woking, Surrey, GU21 6DB. 



This message contains information that may be privileged or confidential and is the property
of the Capgemini Group. It is intended only for the person to whom it is addressed. If you
are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,
 distribute, or use this message or any part thereof. If you receive this  message in error,
please notify the sender immediately and delete all  copies of this message.


Mime
View raw message