aspose file tools*
The moose likes Struts and the fly likes using struts html:form without  action attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using struts html:form without  action attribute" Watch "using struts html:form without  action attribute" New topic
Author

using struts html:form without action attribute

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
I am using <html:form> to transfer my request data.

but i dont want to use the action attribute of the tag. because there is more than one button to make different requests, which i will handle wuth javascript. is there any way where i can use <html:form> without action attribute. i am getting the request parameters using requset.getParameter() method when i am using javascript,which i dont want to do instead of
MyForm mfm=(MyForm)form in my execute method..


regards,
surendar prabu.


SCJP 1.4
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
is there any way where i can use <html:form> without action attribute

No. The action attribute is required for a <html:form> tag. Even if you end up changing it to something else, the original action must be there.

Struts has to have an action in order to know which ActionForm bean to associate with the page.

That shouldn't prevent you from using JavaScript to change the action of the form if you need to. The JavaScript statement:

will work just fine in a Struts JSP.

One word of caution, though. If you plan to use the ActionForm in the NewAction class, you need to make sure that the action mapping for NewAction uses the same form bean as the original action defined for the page. The ActionForm defined for the original action is the one that will be populated by Struts and passed on to the execute method of the Action class.

You might look into using DispatchAction. It sounds like this would be a good fit for what you're doing. Here is a good article on how to use it.


Merrill
Consultant, Sima Solutions
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Originally posted by Merrill Higginson:
[QB]
will work just fine in a Struts JSP.

Thanks merill

but for using the bit of code what you have given the <html:form> tag should allow an attribute called id or name which is represented by your
myForm.

I will look into dispatch action.

regards
surendar prabu
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In a Struts JSP, the name of the form is always the name specified in the Action Mapping in the struts-config.xml file.

For example, if this is your Action Mapping:

<action name="myForm" path="/myAction" type="com.myCompany.MyAction" />

When you specify:

<html:form action="/myAction">

The name of the form will be "myForm" because that's what was specified as the name for the Action Mapping of the Action used by this form.
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Thanks merill,

thanks for your help in all the threads. i resolved many of my problems.

regards,
surendarprabu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using struts html:form without action attribute