I think raghavendra is right.
Rivka, your code is working because you are using primitive type int and not
the wrapper type Integer.
In case of primitive type in case of any exception, it gives you a default
value.


Thanks and Regards, 
Nitish Kumar 




-----Original Message-----
From: Rivka Shisman [mailto:[EMAIL PROTECTED]
Sent: Monday, July 11, 2005 5:13 PM
To: Struts Users Mailing List
Subject: RE: Using struts forms as Value Objects: your opinion?


Hi Borislav

I did the test and it works fine - 

In my form I have:

private int question_no;

public void setQuestion_no(int i) {
     this.question_no = i;
}

public int getQuestion_no() {
    return question_no;
}

public ActionErrors validate(ActionMapping mapping,
            HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        
      if (action.equals("create")){      
        
           if (question_no <= 0) {
                    errors.add("question_no", new
ActionMessage("error.field.positive_num","מספר שאלה"));
            }
        }
}

I don’t have anything regarding this field in struts-config (should i?)

When I insert "abc" in the html:text field that is related to that integer
property - I get the error message I expected to get - " the value in
question_no field must be positive"

 
-----Original Message-----
From: Borislav Sabev [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 11, 2005 11:27 AM
To: Struts Users Mailing List
Subject: Re: Using struts forms as Value Objects: your opinion?

Rivka Shisman wrote:

>Hi again
>
>When you say that validation doesn't work when inserting "ABC" in an
>integer field - do you mean when using struts Validator?
>I'm not using the Validator - I just add "if myInteger < 1 " in method
>validate().
>
>If I define myInteger as String - how do I check that it's a valid
>number in the validate() method (without using Validator)?
>
>  
>
Doesn't matter if you use validation or not, if you define a form 
property as Integer for example (in the form class and in struts-config) 
and then if you write "abc" in this field, you will get a 
ConversionException because the first step that Struts makes in the 
RequestProcesor is to "populate" the form bean i.e. to match the 
parameters that are comming with the request and "transform" them to the 
form proiperties.
After that the validation works, but even if you don't validate the 
forms with the Validator, the populations you can't avoid or change. 
Thus you are forced to define your form properties as String (because in 
the http request anyway they ARE strings, just Struts during the 
population tries to convert them to the types defined in struts-config).
Just make a little test and you will udnerstand the problem ...
Borislav
****************************************************************************
**********************
The contents of this email and any attachments are confidential.
They are intended for the named recipient(s) only.
If you have received this email in error please notify the system manager or
the 
sender immediately and do not disclose the contents to anyone or make
copies.

** eSafe scanned this email for viruses, vandals and malicious content. **
****************************************************************************
**********************

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

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

Reply via email to