• 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 - Yet another combobox prepopulation using prepare method question

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Remi Komornicki
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic