Galbreath, Mark wrote:
 > Your nomenclature is counter-intuitive.
 >
 > Mark
 >

So this explanation should make it a little clearer what I was saying.




In Java primitive cannot be passed by reference so six months ago
in a possibly now defunct project I wrote a Java ``Union'' class.

class RefValUnion {
                
      String stringVal;
      int  intVal;
      float floatVal;
      double doubleVal;
      Date dateVal;
      BigDecimal  decimalVal;
      ...

}


In this project I used a master or superclass base action form
to add validation and other extended functionality
For instance I created all the utility date validation
and financial input validation routines in this class


class SuperActionForm extends ActionForm {
     boolean validateDate( String  input, RefValUnion refval  )
     {
        ...
     }

     boolean validateBigDecimal( String  input, RefValUnion refval  )
     {
        ...
     }


}



I created ActionForms for the project that extended the master
like this one below. In the validate method I used the
validate method in the super class to check the user input.
All the validate methods return boolean value true or false.
If the result is false then the validation failed
otherwise the validation is successful.
Almost all of the validate methods perform some conversion,
the result is saved inside the reference value union
`RefValUnion' this can be used by programmer.


class CalcTaxActionForm extends SuperActionForm {

     String amountText;
     BigDecimal amount;

     public String getAmountAsText( ) {}
     public void setAmountAsText( String ) {}

     public BigDecimal getAmount() {}
     public void setAmount( BigDecimal ) {}

        
     ...


     public ActionErrors validate(
        HttpServletRequest request, ActionMapping mapping )
     {
        ActionErrors errors = new ActionErrors();
        
        // Check user ``tax'' input. I create a reference value
        // union

        RefValUnion refVal = new RefValUnion();
        if ( validateBigDecimal( amountText, refVal )) {
            // Conversion worked. The validate method
            // saved the conversion result in the union
            // so I can use it.
            amount = refVal.decimalVal;
        }
        else {
            // Otherwise conversion failed. As normal add a new
            // error method to the collection and continue
            errors.add( new ActionError( ... ));
        }
        
        // More validation here.

        return errors;
     }

}


I think too fast for my typing hands sometimes.


The fact is that David Winterfeld's ``Validator'' could have perhaps
saved me from the developing the validate methods in the
super class several months ago. Damn! That is why pick on it
as soon as I saw the chapter 11 uploaded into the
TheServerSide.com. It looks very useful and since the ``Validator''
can validate any JavaBean, then it gave me the idea to use it
against an Enterprise JavaBean or if it can work with mapped
property types then inside the Expresso Framework against a DBObject.

Cool! I hope understood better

-- 
Peter Pilgrim          +-----\ +-++----++----+
Java Technologist      |     | | ||    ||    | 'n' Shine
                        |  O  | | ||  --+| ---+
          /\            | ._  / | | \  \ |    |
         /  \           | | \ \ | |+--  || ---+ A new day
        /_  _\  "Up"    | | | | | ||    ||    | is coming
          ||            +-+ +-+ +-++----++----+
<home page="http://www.xenonsoft.demon.co.uk/"; />



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to