Form validations in Struts :-
- Checking pattern and format of the form date before it is getting used the input values of business logic or request processing logic is called as “FormValidation”.
Example: – checking whether E-mails Id is having. @, symbols are not? Checking whether required fields are typed or not?
- We can develop form validations logic in two ways:
1) Client side logic
2) Server side logic
- Verifying whether username and passwords are typed or not comes under form validation logic.
- Verifying whether username and passwords are correct or not, by chicking against database table under business logic.
Classic java web application:
Form validations are two types:
- Server side : Place java code in Servlets Jsp programs before business Logic code or request Processing code.
- Client side : Place javaScript code or VBscript code.
- Java Script is given by Netscape organization as a scripting language and it is no way related the programming language java.
- The technology whose code must be embedded with other technology based program for execution is called as Scripting technology.
- Java Script code executes along with html code, so javascript is called as scripting technology.
- In the client side Script code based form validation logic comes to browser window along with form page for execution. Where as server side form validation logic, executes along with server side web resource programs. (Like Servlets, JSPs)
- Prefer logic working with client side form validations logic (as java script code) because it reduces network round trips b/w browser window and web server. Now a day’s programmers are preferring to add both client side and server side form validations to get the guaranty that form data would be validated by using server side form validation logic, even though client side script code execution is disabled through browser settings.
Client side Form validations :-
- Programmatic mode.
- Declarative mode.
Server side Form validations :-
- Programmatic code.
- Declarative code. (Validator plogin)
- Declarative form validation means working with xml entities to use the readily available form validation logics.
- Programmatic form validation means developing the form validation logics manually.
- The Struts software supplied validation plugin can perform both client side and server side form validation in declarations in declarative mode for Struts applications.
Struts Application :
Form validations
Client side:
Programmatic form validations
- Use java script code explicity inForm page
Declarative form validations
- Use validator plugin
Server side:
- write java code in validate (-,-) of form bean class.
- Use validator plugin
Note: – when the validator plugin is used for Server side form validations then it generates java code based form validation logic.
Similarly when it is used for client side form validations then it generates javascript based form validation logic.
for to perform form validations in a better way it is recommended to mix-up programmatic form validations with valid plug in based declarative form validations while working with Struts applications.