The simplest way to prepopulate a form is to have an Action whose sole purpose is to populate an ActionForm and forward to the servlet or JSP to render that form back to the client. A separate Action would then be use to process the submitted form fields, by declaring an instance of the same form bean name. The struts-example example application that is shipped with Struts illustrates this design pattern nicely. Note the following definitions from the struts-config.xml file: ... <form-beans> ... <-- Registration form bean --> <form-bean name="registrationForm" type="org.apache.struts.webapp.example.RegistrationForm"/> ... </form-beans> ... <action-mappings> ... <-- Edit user registration --> <action path="/editRegistration" type="org.apache.struts.webapp.example.EditRegistrationAction" name="registrationForm" scope="request" validate="false"/> ... <-- Save user registration --> <action path="/saveRegistration" type="org.apache.struts.webapp.example.SaveRegistrationAction" name="registrationForm" input="registration" scope="request"/> ... </action-mappings>
Note the following features of this approach: * Both the /editRegistration and /saveRegistration actions use the same form bean. * When the /editRegistration action is entered, Struts will have pre-created an empty form bean instance, and passed it to the execute() method. The setup action is free to preconfigure the values that will be displayed when the form is rendered, simply by setting the corresponding form bean properties. * When the setup action completes configuring the properties of the form bean, it should return an ActionForm that points at the page which will display this form. If you are using the Struts JSP tag library, the action attribute on your <html:form> tag will be set to /saveRegistration in order for the form to be submitted to the processing action. * Note that the setup action (/editRegistration) turns off validation on the form that is being set up. You will normally want to include this attribute in the configuration
This is a very popular question these days. In general, JSF is still fairly new and will take time to fully mature. However, I see JSF being able to accomplish everything Struts can, plus more. Struts evolved out of necessity. It was created by developers who were tired of coding the same logic again and again. JSF emerged both from necessity and competition. Struts has several benefits: * Struts is a mature and proven framework. It has been around for a few years and deployed successfully on many projects. The WebSphere Application Server admin console is a Struts application. * Struts uses the Front Controller and Command patterns and can handle sophisticated controller logic. * In addition to the core controller function, it has many add-on benefits such as layouts with Tiles, declarative exception handling, and internationalization.
There are disadvantages:
* Struts is very JSP-centric and takes other frameworks to adapt to other view technologies. * Although Struts has a rich tag library, it is still geared towards helping the controller aspect of development and does not give a sense that you are dealing with components on a page. Therefore, it is not as toolable from a view perspective. * Struts requires knowledge of Java™. Its goal was to aid Java developers, but not to hide Java. It does not hide details of the Java language to Web developers that well. * ActionForms are linked programmatically to the Struts framework. Therefore, to decouple the model, you need to write transfer code or use utilities to move data from Action Forms to the Model on input.
JSF is an evolution of a few frameworks, including Struts. The creator of Struts, Craig McClanahan, is one of the JSF specification leads. Therefore, it is not by accident to see some overlap between Struts and JSF. However, one of JSF's major goals is to help J2EE Web applications to be easily developed using RAD tools. As such, it introduces a rich component model. JSF has several advantages: * JSF is a specification from Sun® and will be included in future versions of the J2EE specification. All major vendors are pledging strong support for JSF. * JSF uses the Page Controller Pattern and therefore aids in Page rich applications. Components can respond to event from components on a page. * JSF
A Great Tutorials Portal
Aquarian Infotech System
Copyright © 2008 interviewmaterial.com. All rights reserved.