Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STRUTS 2 Repopulale

 
gopi thulasidoss
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.



 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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());
}

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic