« Redhat to bundle... | Main | FreeRoller OSCache... »

Struts Validator and java.math.BigDecimal.

I've been working feverishly against a Friday deadline, having lots of fun, and learning more than I ever wanted to know about Struts, Hibernate, XDoclet, etc. I'm the closest thing that we have on the project to a Struts expert, so I've had to come up to speed fast on Struts Tiles, Struts Validator, and XDoclet's Struts support. So far, so good, but now I've hit a snag. I've run up against what appears to be a serious Struts Validator limitation: no support for java.math.BigDecimal.

I tried using the double validator, but when I apply the XDoclet tag for the double validator to a field that is a BigDecimal, XDoclet does not generate an entry for the field in validation.xml. Maybe, if I can fix this I can get away with using the double validator. Hmmm...

To resolve this problem the right way, it seems that I'll need to write my own validator. No problem right? I think this involves four steps:

  • Provide a class with a validateBigDecimal() method for server-side validation.
  • Write the JavaScript for client-side validation.
  • Write the XML for my validator and put it in validator-rules.xml.
  • Fetch XDoclet from CVS and hack the Struts Validator support to handle my new validator.

That last step is a doozy. There's got to be an easier way, but googling turns up nothing. I guess I have figured out how I will spend my evening.

Comments:

No worries on the XDoclet side of things. What exactly do you need support for? Is your form bean using a String datatype? If so (as it should be!!!!) then there is no XDoclet change at all.... just use @struts.validator type="bigdecimal" (or whatever you call it). If you need to support another form bean field type - well, I'm going to have to ask why you aren't using a String type before making or allowing that change - although its no big deal to add a type to the Struts Validator support in XDoclet and I'd gladly make that change for you.

Posted by Erik Hatcher on August 12, 2003 at 07:39 AM EDT #

p.s. I'd recommend you write a custom validator to experiment with whatever you need - we do this in lots of situations in fact. Rather than hacking at Struts or Validator code, write a custom class with the same signatures and stuff, plug in your own custom config (the Struts config allows for multiple Validator files), and test it out.

Posted by Erik Hatcher on August 12, 2003 at 07:42 AM EDT #

reyt

Posted by Unknown on September 03, 2003 at 07:10 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed

« Redhat to bundle... | Main | FreeRoller OSCache... »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Java, some may be related to this entry.