Procedure to work with StrutsDemoApp1 application with programmiticDynamicFormBean

Procedure to work with StrutsDemoApp1 application with programmiticDynamicFormBean:

Step1:- Develop FormBean class as shown below manually

RegisterForm.java

Package app;

Important org.apache.Struts.action.*;

Important org.apache.Struts.validator.*;

Important java.servlet.http.*;

Public class RegisterForm extends dynaValidatorForm

{

//no formbean properties

// no setxxx (-,-) & getxxx (-,-)

Public ActionErrors validate (-,-)

{

// call super.validate (-,-) to perform validation plug-in based form validations

ActionErrors errs = super.validate (mapping, req);

// read form data from form bean properties

String user = (String) get (“username”);

String pwd = (String) get (“password”);

// develop custom form validation logic (programatic)

// check whether user & pwd are having same length or not

If (errors.size () == 0)

{

Errors .add (“unpwderr”, new ActionMessage (“my.unpwd.len”))

}

}

S.o.pln (“size of error is” + errs.size ());

Return errs;

} // validate (-,-)

}

To compile this source file add commons-beanutil-1.7.0.jar file in class path as addition jar file.

Step2:- configure the above form bean class in struts configuration filr along with form properties.

In Struts-config.xml file:-

<s-c>

<form-beans>

<form-bean name = “rf” type = “app.RegisterForm”>

< form-property name = “username” type = “java.long.String” initial = “ramu”/>

< form-property name = “password” type = “java.long.String” />

</form-bean>

</form-beans>

Step3:– write following code is RegisterAction.java to read form data from form bean class object.

Same as step(3) of working with declarative dynamic form bean [ref.previous scanerio] but write type casting stmt as show below.
Register fm = (RegisterForm) form;

Step4: – keep the remaining resource as it is.

  • Both DynaActionForm & DynaValidatorForm can generated FormBeans dynamically but DynaActionForm cannot work with validator plug-in where as DynaVakidatorForm can work with validator plug-in.
  • For complote example application that uses programaticDynamic bean and all the 3 appraoches to mixup our form validation logic with validator plug-in refer supplymentory handout given on 25/8/11
  • Example Application that uses maximum validator rules of validator plug-in along with dynamic FormBean utilization (Declarative):-
  • Nve- no form validation errors
  • Ve- validation Errors are there.
  • W.r.to above diagram (5)? indicates that ActionServlet perform validator plug-in based form validations on form bean data based on the entries placed in validation.xml and validator-rules.xml file.
  • For the above diagram based application refer application (4) of the booklet page no. 26-30.
  • When form page having multiple components then it is recommended to develop context in that form page as html table context to make to alignment form easily in the web page.

Question: why Application Parameter is removed from struts 1.3 to configure properties file?

Answer:    This application init parameter allows to configure only one property as a time. So it is recommends to use <message-resource> tag of <s-c>.xml file to configure multiple properties files….

  • Once java.sql.Data class object is given to jdbc driver it is a responsibility of jdbc driver to insert date value in the table column is the pattern i.e supported by underlying database software.

Converting string date value to java.sql.date class object when given date value pattern is yyyy-mm-dd.

String s = “2012-4-24”;

Java.sql.date sqdl = java.sql.date.valueOf (s);

  • Converting string date value to java.sql.date class object when given date value pattern is any pattern.

String s = “10-10-1983”;  // mm-dd-yyyy

//get java.util.date object

simpleDateFormat sdfl = new simple DateFormat (“mm-dd-yyyy”);

java.util.Date udl = sdfl.parse(s);

//get java.sql.Date object

Long ms = udl.get Time ()

Java.sql.Date sqd2 = new java.sql.Date (ms);

Leave a Reply

Your email address will not be published. Required fields are marked *