why do we typecast ActionForm into our plain java bean
class in Action class? What is the reason?

Answer Posted / supra

Use ActionForm to work on session data

In a Struts-based Web application, each ActionForm extends
org.apache.struts.action.ActionForm. These ActionForms
encapsulate page data and provide a validation framework to
validate request parameters.

Most Web applications maintain data in session to make them
available throughout the application. This best practice
addresses this Web application feature. It allows methods
toSession() and fromSession() to move session data to and
from the form data. Thus, it addresses session data
maintenance in a Web application.

To adhere to this practice, follow these steps:

Create an abstract class named BP3Form by extending
org.apache.struts.action.ActionForm.
In BP3Form, add methods with access modifiers as in public
abstract void toSession(SessionData sessionData) and void
fromSession(SessionData sessionData).
In every ActionForm, extend BP3Form and implement the
abstract methods in which the form data is transported to
and from the session.
The corresponding Action class may determine the order in
which these methods are called. For example, you could
invoke method toSession() on the ActionForm just before
actionForward is determined.
When to use this practice

This practice is most useful when session data is
maintained as a single object and/or every page manipulates
or uses session data.

Is This Answer Correct ?    1 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the differences between http direct and http indirect?

669


What design patterns are used in struts?

742


How do struts work?

689


What is the purpose of @createifnull annotation annotation?

810


What is execute method in struts?

680


What is request processor and how does it relates to action mapping?

795


What is difference between struts1 and struts2?

672


what is meant by Struts Validator Framework?

766


What's the purpose of execute method of action class?

686


What is struts2 framework?

695


How do I install struts?

778


What do you mean by actionservlet?

762


What’s the difference between struts and turbine? What’s the difference between struts and espresso?

730


Can you explain value stack?

710


What are the different kinds of actions in struts?

778