Monday, July 7, 2008

Struts 1.2 validator framework tutorial

Hey guys I search for this topic but i couln't find a simple tutorial for this topic.

so i thought to post what i know on this...

i recomend u to practice Struts basics tutorial on before this Netbeans official site.

1. new project>web>web application
2.struts1.2.9 JSP>anyname
i named mine as 'sampleJSP.jsp'

4.add html taglib
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="h" %>

5. Add a form tag to JSP using tag lib
< action=" " onsubmit=" ">
< property="name">
< value="OK">
< / html:form>
6.Create New StrutsActionForm
*important: superclass should be org.apache.struts.validator.ValidatorForm

7. Make getters and setters for text field in JSP

(if u create a propety called 'name' you dont need to do this, bcoz
Netbeans defaultly create for String 'name and int 'number'
8.Create New StrutsAction
*important: Action path should be same as JSP forms action
(the Action path you give here can give in JSP)

9.edit validation.xml

< name="NameForm">
< property="name" depends="required">
< key="">
< /field>

< /form>

10.add '' to properties file

11.Add these to JSP page
< formname="NameForm">
< /head>

< action="name" onsubmit="return validatenameForm(this);">

12. Add Server side validation to work in browsers where javascript doesn't work

< html:errors/>

Final view of sampleJSP...

12. Now run your application

try it and comment plz...

No comments: