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
What are the advantages of spring mvc over struts mvc?
What is the purpose of @element?
How action mapping is configured in Struts?
What is java struts?
What are the main classes which are used in struts application?
Which class of struts is responsible to converts data types from string and vice versa?
What is interceptor struts2?
In struts.xml, what does the attribute "method" stands for in the "action" tag?
Explain struts?
Is struts compatible with other java technologies?
What is the purpose of plug-in tag in struct-config.xml?
Can you explain the directory structure for a struts folder in brief ?
How is a lookup dispatch action created?
What is the differences between struts1 and struts2?
What is struts framework in java?