IntelliJ Java IDE
The moose likes Struts and the fly likes action without form Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Struts
Reply Bookmark "action without form" Watch "action without form" New topic
Author

action without form

Satish Kulkarni
Ranch Hand

Joined: Jul 19, 2003
Posts: 60
Hi,
Is it possible to have an action without a form associated with it?

Regards,
Satish
Jagdeep Singh
Ranch Hand

Joined: Oct 14, 2002
Posts: 106
Nope....you must need a form, even though it is empty.


Jagdeep Singh<br />SCJP;SCWCD;IBM Certified XML Solution Developer;SCBCD1.3
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 23635

Satish,
You do not need a form bean to have an action. One of the examples on the struts home page is:

Just keep in mind that you can't access the ActionForm. That shouldn't be a problem though.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Certs: SCEA Part 1, Part 2 & 3 & Core Spring 3, OCAJP
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
In this case, how can I invoke the forward action?

For forms, when I click a button, I can submit the form and invoke the *action*, how does this work?

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
yah

Its not mandatory to have a form associated with the action what happens in the back is ,the actionservlet will look for formbean in the struts-config ,if it exists an instance of it will be created and the data will be populated in that.If it doesnt have any action then it will just redirect the request to the particular action.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Nicholas Cheung:
In this case, how can I invoke the forward action?

For forms, when I click a button, I can submit the form and invoke the *action*, how does this work?

Nick


Ok this is confusing me now. I thought that the page that submits *to* this action may have a form associated with it but this action is not interested in that form. Do correct me.

thanks
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
To clarify:

Actions *may* have a struts form associated with them. If they do, request parameters that match field names on that form will be populated into the form prior to invoking the action. Additionally, if validate is set to true on the action, the form validate method will be invoked prior to control reaching your action. If there are validation errors, control returns to the input page without ever reaching the action.

Actions can be invoked in many ways:
* Direct request (i.e. the browser URL bar)
* HTML form submit (Post/Get)
* HTTP forward
* HTTP redirect
etc.

When control is transferred to the action, it may or may not use the form. If a form is associated with the action, it may cast it and pull values out. It may just pull values from request parameters. Or it may just forward somewhere else without ever looking at the form.

Hopefully this helps rather than hinders...


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
john guthrie
Ranch Hand

Joined: Aug 05, 2002
Posts: 124
there is nothing is struts that even requires you to use ActionForms. notice that the execute method passes in the http request as a parameter too, so you could use that to get all the form parameters.

dunno why you would though ...
Jagdeep Singh
Ranch Hand

Joined: Oct 14, 2002
Posts: 106
David hibbs....thanx for the detail reply..
 
 
subject: action without form
 
Threads others viewed
use action without actionMapping
Form Submission without ActionForm in Struts 1.3.
Action without ActionForm
Struts -- Action class
javax.servlet.jsp.JspException: Cannot find bean LoginForm in any scope
developer file tools