This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am trying to migrate a struts 1 funcionality to struts 2, and i need to enable /disable, show/hide items in a form, using javascript.
My question is, if i could do a submit in javascript like this:
Only to refresh the form, and make visible another form options:
Could i use an action defined like this, to call a method that only returns
a success? :
And could I add a javascript like this?:
I used to make this, using the returned values in the request or in the session, and forwarding to the form again, in struts 1, but i have no idea how to make this in struts 2.
I'm not really sure what you're asking: ultimately the rendered HTML looks very similar regardless of which version of Struts you're using (and you don't appear to be using JavaScript to hide/show anything, at least not in the sample you posted), and the JavaScript that acts on the form would be nearly identical.
Are you having a specific issue?
Juan Acv
Greenhorn
Joined: Apr 02, 2010
Posts: 18
posted
0
Ok, i don't know how to explain myself, my english is poor, and i know what i want to do, but only in struts 1, and i want to translate it to struts 2.
Well, I will try again:
I have a select, with an "onchange" trigger, because, depending on the value of this select, I will like to show/hide another select:
For example, i have countries, and, for example, if someone select "spain", i want to show another select:
In struts 1, i did it using javascript, making a submit and sending a hidden input value to the action, with this value (will say, a "REFRESH" string) recovered in the request, in the action, the action only makes a forward to the form again, and then, recovering the value from the request, in the jsp, i can make the "if" comparsion (I can put the code, if it is not clear), but i don't know how to make this in struts 2, i am newbie on it, and i realize that the binding beetween actions and jsp's have changed.
I dont know if in struts 2 it is possible to make a "fake submit" only to recover the values that someone have selected, and then, make possible to show/hide another parts on the form.
I can't explain myself better. Maybe it is a stupid question, and it's very easy with the new framework tools, but i am in a hurry, and i try to read about struts 2 as quick as i can, and for my project, i believe i only need to know basic struts 2 and how to develop dynamic forms. if someone can answer me this question, i will be grateful.
It's not a fake submit--it's a real submit. And you're not showing or hiding things using JavaScript--you're using JSTL.
In any case, Struts 2 normally exposes values by exposing an action property as opposed to explicitly setting attributes in the request or session. A publicly-visible getter in the action is all that's needed to send a value to a JSP. You should run through the Struts 2 tutorial on the Struts 2 documentation wiki--it takes only a very short time and will show you all you need to accomplish what you're trying to do.
Juan Acv
Greenhorn
Joined: Apr 02, 2010
Posts: 18
posted
0
Yes, i know that struts 2 now encapsulates the data in beans, what i really don't undertand, it is how to call a specific method in an action or how to say to an action execute() method "now just refresh" or "now save my data", just the way a did it in struts 1.
Ok, sorry, i will take a look to the tutorial and examples.
The action mapping you're using in the JavaScript will work if: that's the complete path, but it should be absolute, not relative; and you're either using Struts 2.1 or you have configured Struts 2 to use extension-less mappings.
Juan Acv
Greenhorn
Joined: Apr 02, 2010
Posts: 18
posted
0
I am using appfuse framework, it works with struts version 2.1.8, and, yes, i believe they use extension-less mapping, reading their tutorial:
After loosing my job, i have been very stressed, into a mess, trying to do this project, that it's very important to me. I have had to learn everything i thought i have learned yet about spring + hibernate, reading lot of documentation, etc...
I have been trying to translate a struts 1 application into struts 2 as quick as i could, instead of being patient and learn struts 2 starting with the basics.