• 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

Struts 2 - altering form action and submitting via a hyperlink

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following form tag:



inside the form, I have the following hyperlink



When clicking on this hyperlink, instead of going to: viewA_doSomething.action, the href is used and attempts to go to 'blah'.

If I use an input (I do however want to use a hyperlink), this does work and submits the form having substituted its action to: viewA_doSomething.action




Do I need to use a different tag to get my hyperlink to correctly submit the form or am I missing something obvious?

Thanks in advance.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really see any link inside the anchor tag, so it's hard to say what might be going wrong.
 
Mark Brownengland
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But that's the whole point. I'm not setting anything in the anchor as I've got an event intercept i.e. onclick which alters the form's action & then submits the form. I'm expecting that on form submission, the action I've altered my form to execute would be invoked upon calling submit(). This does not happen and instead, the location in the href is simply invoked.

I've debugged to check that the action viewA_doSomething.action is not being invoked & I can confirm this is the case.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add a return false; at the end of the onclick event i.e. after submit(); is called. This will stop the browser from following the hyperlink and submit the form...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Mike: I'm saying that when you originally posted your message there was no link, no event ahandlers, no nothing--just the "rel" attribute.

There's no way I could have diagnosed or helped with the information given originally.

Ankit is correct--this is an HTML issue, not Struts. I guess you're not writing your app to degrade gracefully if the user has their JavaScript turned off--that's ok, but it's a decision that should be made consciously.
 
Mark Brownengland
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the earlier confusion. When I first posted, the a link had changed to rel=nolink which I failed to spot but subsequently re-corrected through using alternative character encoding.

I have now rectified this particular problem although I still have the problem in a related post concerning retrieving hidden (s:hidden) attributes in an action that implements RequestAware. I will re-post on the related thread.

In answer to your javascript dependency comment, I wish to make my app interoperable across browsers & local settings as possible as I will have little control over the environment of each user. I have updated my a tag to also forward to the same action, setting each request parameter as part of the URL string.
 
Mark Brownengland
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.
 
Mark Brownengland
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


After further testing, it seems that adding return false has had no impact. To differentiate between submitting from the onclick and the href, I have purposefully made the href a random value in the example quoted below:



On my browser (safari v4.0.3), the return false has no effect & the browser instead attempts to go to the href location i.e. differentAction_mB.action

Is this a browser issue or have I add the return value incorrectly.

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it actually submitting? I wouldn't have thought just putting in submit() would work--I'd guess it's just causing a JavaScript error, which should be obvious if you're using something like Firebug, and doing the regular link processing once the JS errors out. Still not a Struts issue, though.
 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic