struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart" <lukasz.len...@googlemail.com>
Subject Re: Custom validation with Struts2
Date Tue, 18 Mar 2008 11:31:56 GMT
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
-- 
Lukasz

http://www.linkedin.com/in/lukaszlenart

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message