Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question

Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question - Hallo sahabat BEST LEARNING JAVA, Pada Artikel yang anda baca kali ini dengan judul Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan Artikel J2EE, Artikel struts, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question
link : Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question

Baca juga


Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question

Struts supply 2 classes ValidatorForm together with ValidatorActionForm for validating shape fields. Instead of doing basic validation yesteryear using the validate() method inward Action class, these classes allows you lot to leverage rich characteristic of validation framework provided yesteryear Djakarta Struts framework. You tin do declarative validation yesteryear defining rules inward XML config files similar validation-rule.xml or validations.xml equally well. Since Struts is ane of the pop Web MVC frameworks, you lot tin likewise piece of occupation its validation framework on whatever Java spider web application implemented using Struts. Now, coming dorsum to the question, what is the actual departure betwixt ValidatorForm together with ValidatorActionForm inward Struts? They both await quite similar, right?

Well, fifty-fifty though both ValidatorForm together with ValidatorActionForm provides validation back upwardly together with tin survive used to validate shape fields inward Struts application, at that topographic point is a subtle departure betwixt them. The ValidatorForm shape uses the "form name" to perform validation, spell ValidatorActionForm shape uses the "action name" to perform validation inward Struts.

There are clear benefits of each approach. When you lot piece of occupation ValidatorForm thus yesteryear looking at the struts-config.xml file you lot tin clearly nation that a special shape has next validations. But, that's non the instance when you lot piece of occupation ValidatorActionForm, though it provides a to a greater extent than practical way to validate shape fields of a special shape inward Struts.

Sometimes it happens that a unmarried shape is shared amidst many actions together with JSP pages, which agency configuring a unmarried validation for the shape would survive unnecessary. You volition waste product fourth dimension on validating fields which are non related to our page. H5N1 page tin survive distinguished using 'Action' thus yesteryear using ValidatorActionForm you lot tin relieve a lot of unnecessary validation.




Difference betwixt ValidatorForm together with ValidatorActionForm inward Struts

Before looking at the departure betwixt these 2 classes, let's showtime essay to revise roughly basics nigh Validator framework inward Struts. The Validator Framework is used to supply validation of shape fields e.g. you lot tin validate if the password entered inward password champaign has minimum 8 graphic symbol or non together with if non thus you lot tin automatically spend upwardly submission together with present fault messages to the user.

The configuration of Validator Framework inward Struts consist of 2 XML files, validator-rules.xml together with validations.xml file. The showtime ane validator-rules.xml contains the default Struts pluggable validator definitions. You tin add together novel validation rules yesteryear adding novel entries inward this file.

The instant ane validation.xml file contains details regarding the validation routines that are applied to the dissimilar Form Beans. These 2 configuration files should survive placed within the /WEB-INF/lib folder of the application.



Identifier

Thie showtime of import departure betwixt ValidatorForm together with ValidatorAction shape comes from the fact how they are identified. ValidatorForm uses "form name" equally identifier to invoke validation, spell ValidatorActionForm uses "action name" equally identifier to invoke validation


Configuration

In instance of ValidatorForm, the validations.xml together with struts-config.xml file volition survive configured equally following:

Validations.xml
<form-validation>     <formset>         <form name="myForm">             <field property="userName" depends="required">                 <arg key="MyLoginForm.userName"/>             </field>             <field property="password" depends="required,minlength">                 <arg0 key="MyLoginForm.password"/>                 <arg1 key="${var:minlength}" name="minlength" resource="false"/>                 <var>                 <var-name>minlength</var-name>                 <var-value>6</var-value>                 </var>             </field>         </form>     </formset> </form-validation>

struts-config.xml
<form-beans>    <form-bean  name="myForm" type="....."/> </form-beans>  <action-mapping> <action path="/myFormAction" name= "myForm" type=………          />
The key indicate to authorities annotation is that shape shout out should survive same inward both validation.xml together with struts-config.xml file.

In instance of ValidationActionForm, the configuration inward validator.xml together with struts-config.xml await similar below:

 Validations.xml
<formset>     <form-name=”/myFormAction”>         ......     .......     </form-name> <formset>

struts-config.xml
<form-beans> <form-bean  name="myForm" type="......."/> </form-beans>  <action-mapping> <action path="/myFormAction" name="myForm" type=………          />

The key indicate to authorities annotation is that shout out attribute of shape tag contains the action path together with non the shout out of the form-bean itself. If you lot desire to acquire to a greater extent than nigh validator framework, you lot tin farther read Struts inward Action, which covers it inward practiced details.

Example

Let's run into a uncomplicated login representative using the DynaValidatorForm. First, nosotros bespeak to do a From Bean that extends org.apache.struts.validator.DynaValidatorForm.

<form-beans>     <form-bean name="MyLoginForm" type="org.apache.struts.validator.DynaValidatorForm">         <form-property name="userName" type="java.lang.String" />         <form-property name="password" type="java.lang.String" />     </form-bean> </form-beans>

Next measuring is to add together validations to the shape fields inward the validation.xml file. Our Form shout out is "MyLoginForm" together with champaign names are "userName" together with "password".

 Struts supply 2 classes ValidatorForm together with ValidatorActionForm for validating shape fiel Difference betwixt Struts ValidatorForm vs ValidatorActionForm - Interview Question


The validation.xml file contains the next code.
<form-validation>     <formset>         <form name="MyLoginForm">             <field property="userName" depends="required">                 <arg key="MyLoginForm.userName"/>             </field>             <field property="password" depends="required,minlength">                 <arg0 key="MyLoginForm.password"/>                 <arg1 key="${var:minlength}" name="minlength" resource="false"/>                 <var>                 <var-name>minlength</var-name>                 <var-value>8</var-value>                 </var>             </field>         </form>     </formset> </form-validation>

As I said inward the previous paragraph that the shout out attribute of shape tag should survive the shout out of the shape you lot desire to associate amongst the Validation Framework. Name of the shape specified hither should likewise check amongst the ane specified inward the struts-config.xml file. Once you lot did this configuration,  you tin associate each belongings of the shape edible bean amongst ane or to a greater extent than predefined validation rules.

Btw, If you lot desire to acquire to a greater extent than nigh Struts 1.x thus I advise you lot reading Programming Djakarta Struts, sec Edition by Chuck Cavaness.

 Struts supply 2 classes ValidatorForm together with ValidatorActionForm for validating shape fiel Difference betwixt Struts ValidatorForm vs ValidatorActionForm - Interview Question


In the instance of ValidatorActionForm, since validations are tied upwardly amongst activity path together with non amongst form, it's possible to reuse the same shape for dissimilar validations depending upon activity path equally shown below:

&lt;form-validation&gt;     &lt;formset&gt;         &lt;!-- validation mapping for action 1 --&gt;         &lt;form name="/myAction1"&gt;             ...         &lt;/form&gt;     &lt;/formset&gt;     &lt;formset&gt;         &lt;!-- validation mapping for activity 2 --&gt;         &lt;form name="/myAction2"&gt;             ...         &lt;/form&gt;     &lt;/formset&gt; &lt;/form-validation&gt;

This gives you lot to a greater extent than flexibility inward damage of code reuse together with specifying validations based upon requirement.

This is likewise ane of the good Struts interview questions, equally it allows you lot to banking concern check if the candidate has used Struts validator framework or not. Let's run into a yoke of to a greater extent than points to empathize the departure better. I bring seen this inquiry many times on Java spider web developer interviewer where chore description mentioned nigh Struts. Don't retrieve Spring MVC has completely killed the Struts framework, similar Java Swing, at that topographic point are a lot of existent basis projection nevertheless exists in Struts 1.x and Struts 2.x and that's why Java developer amongst cognition of Struts framework are ever inward practiced demand.


That's all nigh the difference betwixt ValidatorForm together with ValidatorActionForm inward Struts framework. It's ameliorate to piece of occupation ValidatorForm because it's clear to run into which shape has validations, simply sometimes it happens that a unmarried shape is used yesteryear multiple Action classes inward JSP pages. In this case, configuring a unmarried validator for the shape would survive overkill. Since the validation rules of a ValidatorActionForm are non assigned to an activity shape simply to the activity (/path-to-action.do). So it is likewise possible to reuse a edible bean inward multiple actions simply to define dissimilar validations for each action.

Further Learning
Java Web Fundamentals By Kevin Jones
Struts 2 Framework for Beginners
Spring Framework Master Class - Beginner to Expert




Demikianlah Artikel Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question

Sekianlah artikel Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question dengan alamat link https://bestlearningjava.blogspot.com/2019/03/difference-betwixt-struts-validatorform.html

Belum ada Komentar untuk "Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel