• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to access forms in action classes

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thin you need to explain the flow more in detail
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic