aspose file tools*
The moose likes Struts and the fly likes Struts 2 - Yet another combobox prepopulation using prepare method question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - Yet another combobox prepopulation using prepare method question" Watch "Struts 2 - Yet another combobox prepopulation using prepare method question" New topic
Author

Struts 2 - Yet another combobox prepopulation using prepare method question

Remi Komornicki
Greenhorn

Joined: Mar 26, 2010
Posts: 4
Hello everyone,

I have spent hours trying to use the Prepare interceptor to populate a list to be used in my combobox for my form. At first it would not execute unless I submitted the form once.
I then realized I needed to access my form through the Action and not directly through the .jsp address!

Now, as I call the action, the prepare() method is executed, populating my list, but the execute() method is executed automatically after, thus returning "success" and sending my form to the success page, without having rendered the contents of the form in my browser, nor taken into account the validation process.


Here is my struts.xml file:




My Action file:



My .jsp file:


What I simply want is to populate my list, then show my .jsp page in my browser, have it filled in and passed through validation (using the prepare method again if validation fails, like I read I needed to do), and then when the validation is ok, go to my succes.jsp page.

I hope I gave enough information (this is my first time here). I have a feeling my problem is either caused by a lack of attention or a fundamental aspect of Struts that I missed (I have started using this framework very recently.

Thanks in advance.
Remi.
Remi Komornicki
Greenhorn

Joined: Mar 26, 2010
Posts: 4
Hi,

I'm sorry if my question is stupid but I really need some help on this. I've been playing around with the prepare() function and validation so long that I'm just lost and disoriented.

Thank you in advance,
Rémi.

Sita Marivada
Greenhorn

Joined: Apr 01, 2010
Posts: 14
Remi,
You don't need Prepare interceptor in this case.
Just add one more action and in that action class write a code to get the values for combobox and set it to list.Return a string from that method in action class,so that it in turn renders input.jsp where we need to enter our input.

Thanks,
Sita


Sita Putta
Remi Komornicki
Greenhorn

Joined: Mar 26, 2010
Posts: 4
Hi Sita,

Thank you for your response!

I was lead to think the prepare() method was indispensable, to repopulate my combobox if validation failed:
http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html

Are you saying I can work around this with a "loading" action that would be called before loading my page, and if the validation failed?

Rémi
Remi Komornicki
Greenhorn

Joined: Mar 26, 2010
Posts: 4
Ok it now works! Thank you Sita.

If anyone cares, here's how I did it:

my struts.xml:


my InscriptionLoad class simply creates the list and keeps it in a property:



And finaly I use it in my form very simply. The list "departementList" that is fetched is not in the same action class as the rest of the properties this form is linked to.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 - Yet another combobox prepopulation using prepare method question