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

Reply via email to