|
|
| Struts validation not work properly |
Expert:firdaus zulkafli
hi...
i have a problem with my struts validation framework. i using struts 1.0...
i have 2 page which is:
1)index.jsp ===================================
<%@ page language="java"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <html:link action="/example.do?actLink=addrecord">[Add record] </html:link><br> </body> </html>
2)add.jsp ================================
<%@ page language="java"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<html> <head> <title>JSP for exampleForm</title> <html:javascript formName="exampleForm" /> </head> <body> <html:form action="/example" onsubmit="return validateExampleForm(this)"> <html:errors /> <br> Name: <html:text property="name" /> <br> Age: <html:text property="age" /> <br> Email: <html:text property="email" /> <br> NRIC: <html:text property="nric" /> <br> Address: <html:text property="address" /> <br> <html:submit value="Send"/> </html:form> </body> </html>
index.jsp act as my 1st page & when it load it has 1 link [Add record] which will open add.jsp (form). in this add.jsp i have several fields which requires some validation (client side - javascript).
currently i managed to validate 2 fields (name & age). for the rest, when i try to put 1 more validation (let say for email), i could not click on [Add record] link to open add.jsp.
but when i remove it, it can open the add.jsp, it seems like it's only allowed for 2 fields to be validated. what have i missed? is there anything that i forgot...
pls help to advise, i face it for almost a week now...
this is my action class...
========================================
public class ExampleAction extends Action {
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
String link = (String) request.getParameter("actLink");
System.out.println("actLink----------->"+link);
return mapping.findForward(link); }
}
my bean class...... =========================================
public class ExampleForm extends ValidatorForm { //Eigenschaften der Klasse private String actLink; private String name; private int age; private String email; private String nric; private String address; public String getActLink() { return actLink; } public void setActLink(String actLink) { this.actLink = actLink; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getNric() { return nric; } public void setNric(String nric) { this.nric = nric; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
my struts-config.xml ====================================== <form-beans > <form-bean name="exampleForm" type="de.laliluna.tutorial.validatorform.form.ExampleForm" /> </form-beans>
<global-exceptions /> <global-forwards /> <action-mappings > <action attribute="exampleForm" input="/form/index.jsp" name="exampleForm" path="/example" scope="request" type="de.laliluna.tutorial.validatorform.action.ExampleAction" > <forward name="home" path="/form/index.jsp" /> <forward name="addrecord" path="/form/add.jsp" /> <forward name="link1" path="/form/link1.jsp" /> <forward name="link2" path="/form/link2.jsp" /> </action>
</action-mappings>
my validation.xml ===================================== <?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
<form-validation> <global> <!-- An example global constant <constant> <constant-name>postalCode</constant-name> <constant-value>^\d{5}\d*$</constant-value> </constant> end example--> </global>
<formset> <!-- validation mapping for example form --> <form name="exampleForm"> <field property="name" depends="required"> <arg0 key="exampleForm.name"/> </field> <field property="age" depends="required"> <arg0 key="exampleForm.age"/> </field> <field property="email" depends="required"> <arg0 key="exampleForm.email"/> </field> </form> </formset> </form-validation>
|
| Answers |
Hi Friend,
Please visit the following links: http://www.roseindia.net/struts/StrutsCustomValidator.shtml http://www.roseindia.net/struts/address_struts_validator.shtml http://www.roseindia.net/strutstutorial/strutsvalidatorframework.shtml http://www.roseindia.net/strutstutorial/usingstrutsvalidatorframewor.shtml
Hope that it will be helpful for you. Thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|