• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using struts html:form without action attribute

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
surendar prabu
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks merill,

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

regards,
surendarprabu
 
reply
    Bookmark Topic Watch Topic
  • New Topic