Are You Recruiter/Hiring Manager?
Cloud-based Candidate Screening | Online Tests
PMP 1600 Questions
PMP 1600 Questions
1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Tutorial Home

Hibernate

  • Advantage of Hibernate over JDBC
  • Hibernate Setup with an web Application
  • First Hibernate Application
  • Hibernate mapping with Database TABLE
  • Hibernate Data Type-Java Data Type - SQL Data Type mapping
  • One to Many Relation in Hibernate
  • One to Many Relation in Hibernate bi-directional
  • Many to Many Relation in Hibernate
  • HQL: The Hibernate Query Language
  • Criteria Queries
  • Criteria Queries : Equal (eq), Not Equal(ne), Less than (le), greater than (gt),greater than or equal(ge) and Ordering the results
  • Criteria Queries: And OR conditions
  • Hibernate generator to generate id (primary key)
  • prevent concurrent update in Hibernate,slate object updatation in Hibernate,version checking in Hibernate

    Struts


  • Model View Controller (MVC)
  • Model View Controller (MVC)
  • Struts Flow-How Struts Works?
  • Struts Tutorial - Struts Setup- First Struts Action class setup
  • Message Resources
  • Validation Framework
  • Validation Framework-client side
  • ForwardAction
  • IncludeAction
  • DispatchAction
  • LookupDispatchAction
  • DynaActionForm
  • DynaActionForm
  • Struts Tutorial - Mutli-click prevention using struts tokens-Prevent Duplicate Submission
  • Logic Iterate Map and List

    JSP


  • JSP Tutorial
  • Introduction to JSP
  • JSP Comments
  • JSP Syntax
  • JSP Scripting Elements :Scriptlet, expression, declaration
  • JSP Directives
  • implicit objects in JSP
  • JSP Actions
  • Introduction to JSP
  • jsp:useBean
  • The jsp:setProperty Action
  • The jsp:getProperty Action
  • Introduction to JSP

    Spring


  • Spring Tutorial
  • Introduction to Spring
  • Benefits of Using Spring Framework
  • Inversion of Control in Spring
  • Introduction to BeanFactory
  • Dependency Injection in Spring
  • Collections Setter Injection
  • Bean Scopes in Spring
  • Spring IOC Setup Step by Step
  • Bean Lifecycle in Spring
  • ApplicationContext
  • MessageSources in Spring
  • Web Spring MVC framework
  • Developing Your First Spring Web Application
  • Developing Your Second Spring Web Application with Spring Form
  • Developing Your First Spring Web Application with Spring Validation Framework with Code Example
  • Spring integration with Hibernate
  • Struts Tutorial -- Code Examples

    DynaValidatorForm

    In this tutorial you will learn how to create Struts DynaValidatorForm. A regular ActionForm is developed in Java and declared in the struts_config. xml. The JavaBeans properties of a regular ActionForm are created by first defining the instance variable and then adding a getter and setter for that instance variable. A DynaValidatorForm has no associated Java class. Its JavaBeans properties are created by adding the <form-property> tag in Struts Config file.DynaValidatorForm is actually a subclass of DynaActionForm. It implements the validate() method much like the ValidatorForm and invokes the Commons Validator. DynaValidatorForm brings the capability of writing XML based validation rules.

    For Example : you have a EmpForm and you don't want a java class (EmpForm). EmpForm has propertis firstName, lastName, country .
    Follow the below four steps.

    Step 1. Adding DynaValidatorForm Entry in struts-config.xml

    Add the following entry in the struts-config.xml file. The <form-property/> tag is used to define the property for the form bean.

    <form-bean name="EmpForm"   
             type="org.apache.struts.validator.DynaValidatorForm">
             <form-property name="firstName" type="java.lang.String"/>
             <form-property name="lastName" type="java.lang.String"/>
             <form-property name="country" type="java.lang.String" />
    </form-bean>

    Step 2. Add action mapping in the struts-config.xml file:

    Add the following action mapping in the struts-config.xml file:

    <action path="/saveEmp" type="com.techfaq.action.EmpSaveAction"
         name="EmpForm"
         scope="request"
         validate="true"
         input="/jsp/empform.jsp">

        <forward name="success" path="/jsp/success.jsp"/>
        <forward name="failure" path="/jsp/faiure.jsp" />

    </action>

    Step 3. In the Action class.

    public class EmpSaveAction extends Action {
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    DynaValidatorForm empForm = (DynaValidatorForm)form;
    // this is the way you can retrive the value which is set in the JSP Page
    String firstName = (String)empForm.get("firstName");
    String lastName = (String)empForm.get("lastName");
    return mapping.findForward("success");
    }
    }
    }

    Step 4. In the JSP page (empform.jsp)

    <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <html:form>
    <html:form action="/saveEmp" method="post">
    <html:errors/> // this is for display error message from resource bundle in JSP
    <html:text property="firstName" size="30" maxlength="30"/>
    <html:text property="lastName" size="30" maxlength="30"/>
    <html:text property="country" size="30" maxlength="30"/>
    <html:submit>Save</html:submit>
    </html:form>

    Step 5. In the validation.xml - The validation.xml file is where you couple the individual Validators defined in the validator-rules.xml to components within your application

    <form-validation>
    <formset>
    <form name="EmpForm">
    <field property="firstName" depends="required">
    <arg0 key="label.firstName"/>
    </field>
    <field property="lastName" depends="required"> <arg0 key="label.lastName"/>
    </field>
    </form>
    </formset>
    </form-validation>

    Step 6. In the validator-rules.xml - The validator-rules.xml file defines the Validator definitions available for a given application.

    <form-validation>
    <global>
    <validator
    name="required"
    classname="org.apache.struts.util.StrutsValidator"
    method="validateRequired"
    methodparams="java.lang.Object,
    org.apache.commons.validator.ValidatorAction,
    org.apache.commons.validator.Field,
    org.apache.struts.action.ActionErrors,
    javax.servlet.http.HttpServletRequest"
    msg="errors.required"/>
    </global>
    </form-validation>

    Step 8. In the the Resource Bundle. application_resource.properties file //Here you can add localization.

    label.firstName=First Name
    label.lastName=Last Name
    errors.required={0} is required.

    Now in the browser type http://localhost:8080/testApp/EmpForm.jsp

    Don't Enter firstName and lastName in the text box and submit the "Save" BUTTON. the RequestProcessor checks for the validateattribute in the ActionMapping.
    If the validate is set to true, the RequestProcessor invokes the validate() method of the DynaValidatorForm instance.
    If Validate fail the RequestProcessor looks for the input attribute and return to JSP page mentioned in input tag.
    If Validate pass goto Action Class execute() method..
    If Validate fail , In the browser (EmpForm.jsp) you can see. In red color.

    First Name is required.
    Last Name is required.

    In the empForm firstName and lastName are the required filed. So in the above configuration you can see we add for both firstName and lastName. You can see depends="required" - "required" property is defind in validator-rules.xml. In the resource bundle : application_resource.propertis file
    label.firstName=First Name
    label.lastName=Last Name
    #Error messages used by the Validator
    errors.required={0} is required.
    {0} will be filled by (First Name or Last Name) because validation.xml above configuration you have defind
    <arg0 key="label.lastName"/>. and <arg0 key="label.lastName"/>.

    Two major differences between DynaActionForm and DynaValidatorForm

    1) DynaValidatorForm is subclass of DynaActionForm.


    2) A DynaActionForm has no associated Java class. Its JavaBeans properties are created by adding the <form-property> tag in Struts Config file. DynaValidatorForm also do the same with extra Validation with out writting code. DynaValidatorForm use XML to do validation.

    The information you are posting should be related to java and ORACLE technology. Not political.