Home > tech > Struts 2 and WebWork: Validator XML Syntax Trivia

Struts 2 and WebWork: Validator XML Syntax Trivia

I had to write a validator to check if a date entered in a form is not one in the future. I could not find an example of this in the documentation, and had to search around a bit to figure out the right XML syntax.

<validators>
  <field name="someDate">
    <field-validator type="fieldexpression">
      <param name="expression"><![CDATA[!someDate.isAfter(@com.domainlanguage.timeutil.Clock@today())]]></param>
      <message>Please enter a date on or before today</message>
    </field-validator>
  </field>
</validators>

Notice the ‘@’s. Posting this here for anyone who might find it helpful. :-)

PS: We use Eric Evans’ timeandmoney package.

About these ads
Categories: tech
  1. Ted Husted
    May 19, 2007 at 10:07 am

    Since the S2 documentation is a wiki, I added a link to this page as a comment.

    -Ted.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: