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