Message:
The following issue has been closed.
Resolver: Nick Heudecker
Date: Sat, 1 Jan 2005 4:04 PM
It is possible to use the validator for nested POJOs. Here's an example using
DynaForms:
/**
* @struts.dynaform name="personForm"
* type="org.apache.struts.validator.DynaValidatorActionForm"
* validate="true"
*/
public class Person {
private Long id;
private String name;
private String notes;
public void setId(Long id) { this.id = id; }
public Long getId() { return this.id; }
/**
* @struts.validator type="required"
* @struts.validator-args arg0resource="person.name"
*/
public void setName(String name) { this.name = name; }
public String getName() { return this.name; }
/**
* @struts.validator type="maxlength"
* @struts.validator-args arg0resource="person.notes"
* @struts.validator-args arg1value="${var:maxlength}"
* @struts.validator-var name="maxlength" value="4000"
*/
public void setNotes(String notes) { this.notes = notes; }
public String getNotes() { return this.notes; }
}
The problem that many people seem to be having is validating nested objects.
Suppose our Person class has an Address property that we also need to validate.
To do this, we first need to add the appropriate struts.validator tags to the
Address class:
public class Address {
private String line1;
private String line2;
/**
* @struts.validator type="required"
* @struts.validator-args arg0resource="address.line1"
*/
public void setLine1(String line1) { this.line1 = line1; }
public String getLine1() { return this.line1; }
/**
* @struts.validator type="required"
* @struts.validator-args arg0resource="address.line2"
*/
public void setLine2(String line2) { this.line2 = line2; }
public String getLine2() { return this.line2; }
}
With that done, we just need to add the struts.validator tags to the Address
setter in the Person class:
/**
* @struts.validator
*/
public void setAddress(Address address) { this.address = address; }
The nested properties will now be validated as you expect.
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/xdoclet/browse/XDT-1136
Here is an overview of the issue:
---------------------------------------------------------------------
Key: XDT-1136
Summary: use of Struts Valdator for POJOs
Type: New Feature
Status: Closed
Priority: Major
Resolution: FIXED
Original Estimate: Unknown
Time Spent: Unknown
Remaining: Unknown
Project: XDoclet
Components:
Apache Module
Versions:
1.2.2
Assignee: xdoclet-devel (Use for new issues)
Reporter: G�tz Boesler
Created: Fri, 5 Nov 2004 2:56 AM
Updated: Sat, 1 Jan 2005 4:04 PM
Description:
In your last Version it is not possible to use POJOs in ActionValidatorForms. I
need a lot of input fields in my project and use therfore already setter and
getter of POJOs in the forms, but I could not find out how fields for
validation of nested attributes can be defined with xdoclet. With
indexedListProperty is this possible in struts (see documentation).
I need a solution soon and it would be a lot of work for me, to change now in
my forms from POJOs setter and getter to setters and getters for each
attribute. Please give me an answer, if you plan this feature in the next
version ([EMAIL PROTECTED]). Thank you!
---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/xdoclet/secure/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
xdoclet-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel