Meaningless Drivel is fun!*
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS 2 Repopulale " Watch "STRUTS 2 Repopulale " New topic
Author

STRUTS 2 Repopulale

gopi thulasidoss
Greenhorn

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>
<result>/postjobs.jsp</result>
</action>

<!-- Submit Post job -->

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


Thanks in advance

Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


Hi,

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.

@Override
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


Hi,

Yes


sectorMap = new HashMap<String,String>();
while(rs.next()){
setSectorKey(rs.getString(1));
setSectorValue(rs.getString(2));
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() {
while(rs.next()){
setSectorKey(rs.getString(1));
setSectorValue(rs.getString(2));
sectorMap.put(getSectorKey(), getSectorValue());
}

 
Don't get me started about those stupid light bulbs.
 
subject: STRUTS 2 Repopulale
 
Similar Threads
Problem in struts 2.0 autocompleter tag.
Autocompleter - NoSuchMethodException
S2: autocompleter - how to populate a list based on user's input?
Struts 2 autocompleter not populating from database
Autocompleter