I'm just getting started with Struts2 and I have some questions regarding the usage of the framework.
I want to use the s:action tag to populate a select drop-down list but it does not seem to work. I read
the documentation regarding the s:action tag and I cannot find what am I doing wrong. Are there any
examples of s:action usage to point me to (apart from the extremely trivial ones) ?
Also another issue I have is how can I submit a form to the current page the user is. For example I
have a drop-down list from which the user selects the language he wants, and then submits the result.
I want the user after the submission of the form to be redirected to the same page he was. How can I
achieve that using action mapping on the struts.xml ?
Re question 1: without knowing what you're doing, it's impossible to say what you're doing wrong.
Re question 2: a form tag with no action/etc. will do a postback, although that isn't necessarily what you really want--it depends on your application.
posted 10 years ago
Ok you are probably right maybe I have to elaborate a bit to give you a better understanding of what I'm
In question 1 what I want is to use the s:action tag to provide me with the data to populate a drop-down
list. To be more specific I want to populate a drop-down list with a number of Countries. For this purpose
I created an action (populateCountryList) that its sole purpose is to supply me with the List of Countries
(see code snippet below).
Now in the header of each of my pages I have the code
which fails to populate the drop-down list. Correct me if I am wrong but shouldn't the Countries property be
available on the ValueStack after I used the s:action tag ?
For the second question imagine that while the user changes the Language I want some code to be executed
(so I have to provide some action to the form) and then return to the current page that initiated the submission
of the form . Because this form is in the header page (which is included in several pages) I want to know if
there is a way to tell struts (through struts.xml) to execute an action and then return back to the same page
that initiate the request.
posted 10 years ago
Actually I found the problem related with question 1. I had to add an id attribute to s:action tag, which I
then used to access my property. Hence the new (corrected) code (just in case anybody stumbles to the
same problem) is :
Something must be done about this. Let's start by reading this tiny ad: