File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes STRUTS 2 Repopulale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS 2 Repopulale " Watch "STRUTS 2 Repopulale " New topic

STRUTS 2 Repopulale

gopi thulasidoss

Joined: Sep 07, 2007
Posts: 8
Hi to all,

I am using struts 2 frame work

I have the postjobs.jsp form that i am loading the (select box and autocompleter) from database using(PostJobMainAction).
once loaded, i use another action to submit(PostJobAction).

The problem is When the validation fails it wont repopulate the select box and the autocompleter ............

Hi all waiting for your response..........

My jsp Snippet

<s:autocompleter name="sectorType" list="sectorMap" theme="simple" autoComplete="true" />

postjobMainAction will fetch the setorMap from database.

My struts looks like
<!--Show post job -->
<action name="postJob" class="employer.action.PostJobMainAction">
<result name="input" >/postjobs.jsp</result>

<!-- Submit Post job -->

<action name="addJob" class="employer.action.PostJobAction">
<result name="input" type="dispatcher">/postjobs.jsp</result>

Thanks in advance

Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


First understand when you validate your form and validation called then the flow of your project not reached at your action calss.

So all the variable which is use in jsp initialize again when your validation fail.

so, when you validate every time your validate methid call.

so Override validate methd in your Action class and initialize your comboox list varibale in validate methid. Like.

public void validate() {
yourlistname = listvalue;

all variable which you want to get back when validation failed.

If you have still any problem post your jsp code and action code.

Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684



sectorMap = new HashMap<String,String>();
sectorMap.put(getSectorKey(), getSectorValue());

this code set your sectorMap and display into your jsp.

So, put this code into your validate method.

override validate methid into your PostJobMainAction class and put above code.

public void validate() {
sectorMap.put(getSectorKey(), getSectorValue());

I agree. Here's the link:
subject: STRUTS 2 Repopulale
Similar Threads
S2: autocompleter - how to populate a list based on user's input?
Autocompleter - NoSuchMethodException
Problem in struts 2.0 autocompleter tag.
Struts 2 autocompleter not populating from database