• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access forms in action classes

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am wondering how to access a form object from an action class that the form is not associated with.

So for example, if Form-A is processed in the executeRender() method of Action-A, and the executeAction() method of Action-B needs to view the values in Form-A, how does Action-B see those values?

Would I have to place Form-A in the session or is there a better way?

I hope I explained this ok.

Thanks.
 
Swamy Nathan
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thin you need to explain the flow more in detail
 
sasikiran uvsr
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

the html form elements are stored in a sub-class of ActionForm that u specify in struts-config.xml

the sub-class of Action that u write uses those elements of the action form to perform business logic.

u can import the action-form class that u hav written specifically for this action class.
then in the execute method of the action class that you write

Method Signature :
%%%%%%%%%%%%%%%%%%
public ActionForward execute( ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException
{

---> YourActionForm afObject = (YourActionForm) form;

then u can use the elements via their respective getter methods.

hope this helps....
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a portlet that uses a custom "struts like" framework, so hopefully the differences aren't causing too much confusion.

I have two methods in my Action class:
1. public ForwardConfig executeRender(ActionConfig mapping, RenderRequest request, RenderResponse response) {
2. public ForwardConfig executeAction(ActionConfig mapping, ActionForm form, ActionRequest request, ActionResponse response) throws PortletException {

The first method prepares the form for render. The second method processes the form after it is submitted. Is there an equivalent to these two methods in a regualar Stuts implementation?

So here is a test scenario for what I am trying to do:
Say I have workflow type application with 10 forms (and 10 JSPs). I want to be able to pass the first form to the second form's Action class when the second form's Action is called. Then I want to be able to pass the second form to the third form's Action class when the third form's Action is called. And so on...

Does this explaination help at all?
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic