aspose file tools*
The moose likes Struts and the fly likes Struts2 ajax theme - One form, two buttons.. two actions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 ajax theme - One form, two buttons.. two actions?" Watch "Struts2 ajax theme - One form, two buttons.. two actions?" New topic
Author

Struts2 ajax theme - One form, two buttons.. two actions?

Sandy Noble
Greenhorn

Joined: Apr 30, 2009
Posts: 13
Hi gang, my first post here, but have searched high and low for an answer to this problem that works... To no avail! I hope someone can tell me to keep trying, or to give up!

I have a form for operating a PC seat booking system that I'm trying to put together using the struts2 ajax functionality.
The form has a s:datetimepicker, and a s:select field (for a seat type), and two buttons. I would like each button to trigger a different action eventually, but can't seem to figure out how to do it.

Here is the code I'm working on at the moment (I have a bean called "detail" instantiated in my action, which gets loaded with seatType and seatDateFromString, and submitValue) :



In this the form is POSTed to a handler method in the action, in which I hoped to look at detail.submitValue to see which button was pressed, and then branch based on that. detail.submitValue always just ends up as null.

I also tried

Which works lovely and goes directly to the right methods in the action that I've set up in some s:url, but it doesn't include the rest of the form data that I actually want posting. If I add formId="detailControlForm" to the s:submit tags, then both submit tags revert to submitting the base action associated with the page, though they do include the form fields.

I also tried


Which does the same: triggers Flexi.action (the base action for this page). If I remove the formId="..." from the submit tags, then the correct actions get triggered, but obviously with no field contents included.

I am sure that at least one of these should work! I don't have any interceptors in the interceptor stack however, so I wonder if that takes care of this struts magic in a way I don't understand!

Maybe someone can help me, let me know I am barking up the wrong tree entirely perhaps!

Thanks!

SN
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't have *any* interceptors in the interceptor stack?

Interceptors are how form fields are set to action properties. Interceptors are the *heart* of S2 functionality. Are you *sure* you don't have any interceptors in your default stack?
Sandy Noble
Greenhorn

Joined: Apr 30, 2009
Posts: 13
Hi David, thanks a lot for the reply. You incredulity speaks volumes, and is almost what I was hoping someone was going to say. Yes the interceptor stack is empty (as far as I can see). The application is a bit unusual in that it was snipped weirdly off from a much larger s2 application, and has a few foibles because of that... I was experimenting with ajax-ing it up (wondering slightly why nobody had tried it before - and I guess this is why).

I suppose that's the end of that then. Is it surprising that anything works at all?

Thanks again,
SN
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What makes you think your default interceptor stack doesn't have any interceptors?
Sandy Noble
Greenhorn

Joined: Apr 30, 2009
Posts: 13
David, thanks for you reply. I'd always been told we never had any interceptors in the application, but I think what was meant by that was that we didn't have any custom interceptors, not that interceptors weren't running at all (I could never really understand how _anything_ worked at all, if there were no interceptors - assumed it was some strutsy magic beyond my comprehension at work). Because I've just had a look at the struts-default.xml in my struts core 2.0.9 jar and it's got all the interceptors I'd expect to see there. Rrr.

So I'm back to square one really, except that I notice it's quite an old version of the struts library that we're using, so I wonder if it might be a bug that has been fixed since then?


THanks for your help, very much appreciated.
SN
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you're using the default "xhtml" theme, one issue *may* be that the HTML you're generating is invalid, and different browsers may handle it in different ways. IIRC you can't put div tags around table rows. I'm not saying that's the problem, but it's a potential issue--it'd be easy to test by removing the div tags. Haven't had a chance to think about the actual Dojo/AJAX stuff yet.

If nothing else it's probably worth your while to upgrade to the latest 2.0 version (2.0.14 I think). Moving to 2.1 would necessitate some changes, so it might not be the best option, although if you have the time it's worth it.

One thing to bear in mind moving forward is that the Dojo tags (which are in a plugin in 2.1) have been deprecated because they use such an old version of Dojo and nobody has really signed on to upgrade them to a more recent version (it'd be a lot of work). You may be better served by either (a) using plain ol' Dojo, or (b) using a different JavaScript library altogether.

I'm not saying you shouldn't use the existing Dojo functionality--it'll always work as well as it does now, and makes simple use-cases *extremely* simple and convenient--just wanted to let you know.
Sandy Noble
Greenhorn

Joined: Apr 30, 2009
Posts: 13
Ok thanks David, that's really helpful. I've been diverted onto other stuff right now, but will be coming back to this problem at some point, so will be bear your advice in mind.

Cheers again!
SN
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 ajax theme - One form, two buttons.. two actions?