Erik,
Below is a clipped version of a RegistrationForm.java (from the struts
validation example - struts-validation.war). I've also added in what
would be the current related validation xdoclet tags. I've only
included one type that is not a primitive/supported type to try to get
to the heart of the issue. Currently there is no problem with the
standard String validation, but nothing will be generated for the second
validation tag... setCityStateZip() because it is not a supported type.
I believe this is a result from line 298 in
StrutsValidatorTagsHandler.java (method = getFields()).
if (supportedTypes.contains(type)) {
What I would like to be able to do - validate the city, state, and zip
all separately from within XDoclet. The CityStateZip Object is not a
form object at all... it is a plain old java object. In my particular
case, the object that I need to have validated won't be used anywhere
else so there is no justification for creating a separate form for it
and doing something like your form-within-a-form approach.
EXAMPLE: shortened from struts-validation.war (RegistrationForm.java)
/**
* @struts.action
* name="registrationForm"
* path="/register"
* scope="request"
* unknown="false"
* validate="true"
*/
public final class RegistrationForm extends ValidatorForm implements
Serializable {
private String sAddr = null;
private CityStateZip csz = new CityStateZip();
public String getAddr() {
return sAddr;
}
/**
* @struts.validator
*/
public void setAddr(String sAddr) {
this.sAddr = sAddr;
}
public CityStateZip getCityStateZip() {
return csz;
}
/**
* @struts.validator
*/
public void setCityStateZip(CityStateZip csz) {
this.csz = csz;
}
}
WHAT I WOULD LIKE TO BE ABLE TO DO (or something like it):
/**
* @struts.validator
* fieldname="csz.city"
* type="required"
* msgkey="error.required"
*
* @struts.validator
* fieldname="csz.state"
* type="required"
* msgkey="error.required"
*
* @struts.validator
* fieldname="csz.zip"
* type="required"
* msgkey="error.required"
*/
public void setCityStateZip(CityStateZip csz) {
this.csz = csz;
}
THIS IS CURRENTLY POSSIBLE WITH THE FOLLOWING validation.xml (created
manually, I believe - and a similar technique is presented in the struts
example):
<form-validation>
<formset>
<form name="registrationForm">
<field property="csz.city"
depends="required">
<msg
name="required"
key="error.required"/>
<arg0
key="registrationForm.csz.city.displaylabel"
/>
</field>
<field property="csz.state"
depends="required">
<msg
name="required"
key="error.required"/>
<arg0
key="registrationForm.csz.state.displaylabel"
/>
</field>
<field property="csz.zip"
depends="required">
<msg
name="required"
key="error.required"/>
<arg0
key="registrationForm.csz.zip.displaylabel"
/>
</field>
</form>
</formset>
</form-validation>
Any ideas or thoughts on approach would be great. Right now I
essentially wrote a hack to the validation template for a new tag
(fieldname) and then use empty setter methods with valid supportedTypes
(in my case, String) so that the proper validation.xml is generated.
It's a hacky solution, but it's generating the proper validation.xml for
the time being.
Thanks,
Chris
-----Original Message-----
From: Erik Hatcher [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 4:43 PM
To: [EMAIL PROTECTED]
Subject: Re: [Xdoclet-user] Struts, Validator, non-supported Types
Chris,
I'm really confused by this. I'm the creator of the Validator XDoclet
stuff and here is an example from my project:
public class ContactInfoForm extends BaseForm {
private AddressForm homeAddress;
private AddressForm workAddress;
public AddressForm getHomeAddress() {
return homeAddress;
}
/**
* @struts.validator
*/
public void setHomeAddress(AddressForm homeAddress) {
this.homeAddress = homeAddress;
}
public AddressForm getWorkAddress() {
return workAddress;
}
/**
* @struts.validator
*/
public void setWorkAddress(AddressForm workAddress) {
this.workAddress = workAddress;
}
}
Notice that there are some dummy @struts.validator tags there. This is
an issue that needs addressing to really make this good, but to make it
work currently it has to be tagged this way. Now AddressForm looks
like this:
public class AddressForm {
private String addressLine1;
private String addressLine2;
private String addressLine3;
private String city;
private String stateCode;
private Integer countryId;
private String email;
private String province;
private String postalCode;
private String phone;
private String fax;
// most getters/setters omitted here
public String getEmail() {
return email;
}
/**
* @struts.validator type="email"
*/
public void setEmail(String email) {
this.email = email;
}
}
And validation.xml gets generated just fine with workAddress.email and
homeAddress.email using the "email" validator.
How does this jive with what you are having issues with?
Erik
On Thursday, March 20, 2003, at 03:34 PM, Chris Butler wrote:
> Issue: Validating objects that are "non-supported" types in a form
> with
> methods that should be supported because they *do* return supported
> types.
>
> NOTE: This seems like it would come up often with ValueObjects in
> forms.
>
> Struts has a validator example in which a cityStateZip object exists
> within a form. It is desirable to be able to auto-generate its
> validator.xml by using XDoclet. However, XDoclet (in
> StrutsValidatorTagsHandler.java) currently will bypass any methods
that
> do not return base types.
>
> Currently I do not believe I can generate the following (clip from the
> Struts validation example, validation.xml):
>
> <field property="cityStateZip.stateProv"
> depends="required,mask">
> <arg0
> key="registrationForm.stateprov.displayname"/>
> <var>
> <var-name>mask</var-name>
> <var-value>^[a-zA-Z]*$</var-value>
> </var>
> </field>
>
> FROM STRUTS VALIDATOR EXAMPLE: RegistrationForm.java
>
> public CityStateZip getCityStateZip() {
> return csz;
> }
>
> public void setCityStateZip(CityStateZip csz) {
> this.csz = csz;
> }
>
> So - my solution was to change the XDoclet template
> (validation_xml.xdt)
> to do the following using a new attribute of tag @struts:validator
> fieldname="<somename>". This was accomplished by the below in the
> template:
>
> <XDtMethod:ifHasMethodTag tagName="struts:validator"
> paramName="fieldname">
> <field property="<XDtMethod:methodTagValue
tagName="struts:validator"
> paramName="fieldname"/>"
> </XDtMethod:ifHasMethodTag>
> <XDtMethod:ifDoesntHaveMethodTag tagName="struts:validator"
> paramName="fieldname">
> <field property="<XDtValidator:fieldName/>"
> </XDtMethod:ifDoesntHaveMethodTag>
>
> However, due to bypassing the non-supported type in the
> StrutsValidatorTagsHandler, I'm basically forced to create a faux
> mutator method (String setHackySolutionForMyComplexObject()) and place
> the tag there in order to get it to work properly... since String is
a
> handled type. This ends up being a very hacky solution in my book.
>
> Does anyone have any thoughts on the right way to do this?
Ultimately,
> I know that Struts Validator should handle validating an object as
long
> as the target setter method to validate will use those base types...
> particularly since the core Validator example uses such an object.
>
> Or, if I'm way off-base and there's an easy solution, let me know that
> too. :-)
>
> Chris
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Tablet PC.
> Does your code think in ink? You could win a Tablet PC.
> Get a free Tablet PC hat just for playing. What are you waiting for?
> http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
> _______________________________________________
> xdoclet-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/xdoclet-user
>
-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC.
Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user
-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC.
Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user