• 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

How to set values in select box using request scope

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to populate values in select box while displaying a jsp page. when I use validations, the values in the combo box will be null (if I submit the form with out selecting any value) after getting validated. How to maintain the values in the select box even after validation with out using sessions.

I am using stuts 1.3.

Thanking you.

--raaja g
 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raaja,

Please post the code.
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using mapping dispatch action or lookup dispatch action. I am just pasting the part of the code to get an idea of my approach.

My code is: JSP:
<html:select property="branchId" onchange="getDepartments()" style="textbox" styleId="branchId">
<html:option value="0">Select Branch</html:option>
<logic:notEmpty name="branches">
<html:options collection="branches" property="branchId" labelProperty="branchName" />
</logic:notEmpty>
<logic:empty name="branches">
No branches
</logic:empty>
</html:select>

<html:submit property="method">
<bean:message bundle="documents" key="documents.uploadfile" />
</html:submit>

Struts-config:
<action
name="documentCheckout"
input="/pages/document_checkout.jsp"
path="/documentsByDeptNoProfileCheckout"
scope="request"
parameter="method"
validate="true"
type="com.krishct.efiler.user.actions.DocumentCheckOut">

<forward name="success" path="/pages/document_checkout.jsp"/>
</action>

validation.xml
<form name="documentCheckout">
<field property="departmentId" depends="required">
<msg name="required" bundle="user" key="errors.required"/>
<arg key="user.department" bundle="user"/>
</field>
</form>

action method:

public ActionForward populate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
if(request.getSession(false) == null || request.getSession(false).getAttribute("userId") == null) {

System.out.println("...session fail from DocumentCheckOut.....");
return mapping.findForward("sessionfail");
}
List departments=null,profiles=null,documents,branches=null;
Integer profileId=null,roleId=null,deptId=null,branchId=null,userId=0;
String deptName,branchName,userName;
IUserLocation iUserLocation=new UserLocation();
try {
branches=iUserLocation.getBranch();
request.setAttribute("branches", branches);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("success");
}

public ActionForward documentCheckOut(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
if(request.getSession(false) == null || request.getSession(false).getAttribute("userId") == null) {

System.out.println("...session fail from DocumentCheckOut.....");
return mapping.findForward("sessionfail");
}
IUserLocation iUserLocation=new UserLocation();
List branches=null;
DynaValidatorForm dform=(DynaValidatorForm)form;

Integer status=null;
try {
Integer branchId=(Integer) request.getParameter("branchId");

status=iUserLocation.docCheckOut(branchId);

branches=iUserLocation.getBranch();
request.setAttribute("branches", branches);


if(status>0 ){
messages = new ActionMessages();
messages.add("sts",new ActionMessage("file.checkout.status"));
saveMessages(request, messages);
return mapping.findForward("success");
}
if(status==0 || status.equals(null)){
messages = new ActionMessages();
messages.add("sts",new ActionMessage("file.error.checkout"));
saveErrors(request, messages);
return mapping.findForward("failure");
}
} catch (Exception e) {

e.printStackTrace();
}
return mapping.findForward("success");
}

Problem is if I submit the document without selecting the values validation is happening but the select tag is not populated with the values. It will become empty but if I keep that list object in populate method in session the select tag will be having values even after validation. In my application I have lot of select tags I cant maintain all the values in session. Is there any solution for this.

--raaja g
 
reply
    Bookmark Topic Watch Topic
  • New Topic