Lukasz Lenart wrote:
I'm not sure were is the problem but I've just checked such simple
example below and everything is ok. Maybe you should consider to use
Long instead of Integer, because when you enter more then 2147483647
to the field you will get some strange value back to the input
(because you loose precision ;-)

class EmployeeAction extends ActionSupport {

private Integer cardNo; // getter & setter

 public void validate() {
        if (cardNo == null) {
            addFieldError("cardNo", "Should be integer!");
        } else if ( cardNo < 1 || cardNo > 999999) {
            addFieldError("cardNo", "Should be integer!");
        }
    }
 }

JSP

<s:textfield label="Card Number" name="cardNo" />

Regards


You may also want to consider declarative validation [1], either using an XML file or annotations. Struts has built-in support for validating an integer input is in a given range [2].

As to the problem of getCardNo() always returning 0, that shouldn't happen; you may have a conversion error happening, or perhaps something else is mis-configured somewhere. Struts should call setCardNo() for you to pass the form data in.

L.

[1] http://struts.apache.org/2.0.11/docs/validation.html
[2] http://struts.apache.org/2.0.11/docs/int-validator.html


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

Reply via email to