Hi all ,
I am doing server side validation using validate method inside my action
class.I need to validate the textfield  whether it is a null and if not it
should be numeric.
My jsp page is as follows:- 

<%...@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd";>
<%...@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
   <s:head />
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>Login Page</title>
   </head>
   <body >
    <s:form action="Login">
    <s:textfield label="Load" size="12"  name="load"/>
    <s:textfield label="Duration" size="12" name="time"/> 
   <s:submit theme="simple" action="start"  value="Start" />
   <s:submit theme="simple" action="stop"  value="Stop" />
  <s:submit theme="simple" action="change" value="Change" />
   </s:form>
   </body>
</html>

and my action class is as follows
import com.opensymphony.xwork2.ActionSupport;
public class RemoteClientAction extends ActionSupport {
         public void validate() {
        if (getLoad().length() == 0) {
            addFieldError("load", "Load is required");
          }
         if (getTime().length() == 0) {
            addFieldError("time", "Duration is required");          
        }
         }
        public String getLoad() {
                return load;
        }
        public void setLoad(String load) {
                this.load = load;
        }
        public String getTime() {
                return time;
        }
        public void setTime(String time) {
                this.time = time;
        }
        private String load;
        private String time;
       public String execute(){
      return SUCCESS;
}

Here I am able to validate for not null fields. But I also want to validate
it for the field if not null should be numeric. How Can I do this??
Please Suggest me possible solution in order to validate both things.
-- 
View this message in context: 
http://old.nabble.com/Struts2-Multiple-validation-for-single-field-tp26373102p26373102.html
Sent from the Struts - User mailing list archive at Nabble.com.


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

Reply via email to