jsp page
FormNo2.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/tlds/c.tld" prefix='c'%>
<%@ taglib uri="/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/tlds/struts-html.tld" prefix="html" %>
<%@ taglib prefix="s" uri="/tlds/struts-tags.tld" %>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Budget Form 2</title>
<head>
<html:javascript formName="formNo2"/>
<LINK rel="stylesheet" type="text/css" href="/Gramlekha/css/CalendarControl.css">
</head>
<body>
<html:form action="/Form2" onsubmit="return validateFormNo2(this);">
<div>
<table>
<tbody>
<tr>
<td align="center"><b><bean:message key="label.budget.header"/></b></td>
</tr>
<tr>
<td>
<fieldset>
<legend style="font-size:13px"><b><bean:message key="label.budget.information"/></b>
</legend>
<table border="0" width="100%" cellpadding="5" cellspacing="5" style="font-size: 13px">
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td><bean:message key="label.budget.date"/><b><font color="red">*</font></b>
<html:text property="budgetdate" readonly="true" onfocus="showCalendarControl(this);"></html:text>
</td>
<td><bean:message key="label.budget.tharavno"/><b><font color="red">*</font></b>
<html:text property="tharavno"></html:text>
</td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td><div>
<fieldset>
<legend style="font-size:13px"><b><bean:message key="label.budget.otherinfo"></bean:message></b></legend>
<table border="1" width="100%" cellspacing="0" cellpadding="5" style="font-size: 13px">
<tr>
<td rowspan="2" align="center"><bean:message key="label.budget.srno"/></td>
<td rowspan="2" align="center"><bean:message key="label.budget.mainpoint"/></td>
<td colspan="2" align="center"><bean:message key="label.budget.budgetpoint"/></td>
<td colspan="2" align="center"><bean:message key="label.budget.from"/></td>
<td colspan="5" align="center"><bean:message key="label.budget.to"/></td>
</tr>
<tr>
<td align="center"><bean:message key="label.budget.pointno"/></td>
<td align="center"><bean:message key="label.budget.amount"/></td>
<td align="center"><bean:message key="label.budget.worketc"/></td>
<td align="center"><bean:message key="label.budget.availableamount"/></td>
<td align="center"><bean:message key="label.budget.mainpoint"/></td>
<td align="center"><bean:message key="label.budget.subpoint"/></td>
<td align="center"><bean:message key="label.budget.worketc"/></td>
<td align="center"><bean:message key="label.budget.amount"/></td>
<td align="center"><bean:message key="label.budget.remark"/></td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">2<br><b><font color="red">*</font></b></td>
<td align="center">3</td>
<td align="center">4</td>
<td align="center">5</td>
<td align="center">6</td>
<td align="center">7 <br><b><font color="red">*</font></b></td>
<td align="center">8</td>
<td align="center">9</td>
<td align="center">10</td>
<td align="center">11</td>
</tr>
<tr>
<td> </td>
<td>
<html:select property="selectedItem">
<html:optionsCollection value="id" name="formNo2Dispatch" label="name" property="budgetHeadListMain"/>
</html:select>
</td>
<td>
<html:text property="matterno" size="5"></html:text>
</td>
<td>
<html:text property="budgetamount" size="5"></html:text>
</td>
<td>
<html:textarea property="workfacilitydetails" cols="10"></html:textarea>
</td>
<td>
<html:text property="remainingamount" size="5"></html:text>
</td>
<td>
<html:select property="selectedItemSub">
<html:optionsCollection value="id" name="formNo2Dispatch" label="name" property="budgetHeadListSub"/>
</html:select>
</td>
<td>
<html:text property="subpoint" size="5"></html:text>
</td>
<td>
<html:textarea property="workfacilitydetailsupto" cols="10"></html:textarea>
</td>
<td>
<html:text property="amount" size="5"></html:text>
</td>
<td>
<html:text property="remark" size="15"></html:text>
</td>
</tr>
</table>
</fieldset>
</div>
</td>
</tr>
<tr>
<td>
<html:submit value="Submit"></html:submit>
</td>
</tr>
</tbody>
</table>
</div>
</html:form>
</body>
</html>
Action Form for the above foem is
package com.gramlekha.budget.ActionForm;
import java.util.ArrayList;
import java.util.Date;
import org.apache.struts.action.ActionForm;
public class FormNo2Form extends ActionForm{
//private ArrayList budgetexpendlist=null;
Date budgetdate;
String tharavno;
String budgetexpend;
Integer matterno;
Integer budgetamount;
String workfacilitydetails;
Integer remainingamount;
String subpoint;
String workfacilitydetailsupto;
Integer amount;
String remark;
String selectedItem;
String selectedItemSub;
public String getSelectedItemSub() {
return selectedItemSub;
}
public void setSelectedItemSub(String selectedItemSub) {
this.selectedItemSub = selectedItemSub;
}
public String getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
public String getTharavno(){
return tharavno;
}
public Date getBudgetdate() {
return budgetdate;
}
public void setBudgetdate(Date budgetdate) {
this.budgetdate = budgetdate;
}
public Integer getMatterno() {
return matterno;
}
public void setMatterno(Integer matterno) {
this.matterno = matterno;
}
public Integer getBudgetamount() {
return budgetamount;
}
public void setBudgetamount(Integer budgetamount) {
this.budgetamount = budgetamount;
}
public String getWorkfacilitydetails() {
return workfacilitydetailsupto;
}
public void setWorkfacilitydetails(String workfacilitydetails) {
this.workfacilitydetails = workfacilitydetails;
}
public Integer getRemainingamount() {
return remainingamount;
}
public void setRemainingamount(Integer remainingamount) {
this.remainingamount = remainingamount;
}
public String getSubpoint() {
return subpoint;
}
public void setSubpoint(String subpoint) {
this.subpoint = subpoint;
}
public String getWorkfacilitydetailsupto() {
return workfacilitydetailsupto;
}
public void setWorkfacilitydetailsupto(String workfacilitydetailsupto) {
this.workfacilitydetailsupto = workfacilitydetailsupto;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public void setTharavno(String tharavno){
this.tharavno=tharavno;
}
public String getBudgetexpend(){
return budgetexpend;
}
public void setBudgetexpend(String budgetexpend){
this.budgetexpend=budgetexpend;
}
}
Getter setter method for the value and label
package com.gramlekha.bean;
public class BudgetheadBean {
private Integer id;
private String name;
public BudgetheadBean(){
}
public BudgetheadBean(Integer id,String name){
this.id=id;
this.name=name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLabel(){
return name;
}
public Integer getValue(){
return id;
}
}
And the Actual class to retrieve values from datatase and set it to the combo
package com.gramlekha.Common;
public class budgetList extends DispatchAction{
String head;
Session session=null;
Transaction tx=null;
String target;
SessionManagement sessionManagement = new SessionManagement();
List <Vouchermaster> detailHeadList= new ArrayList<Vouchermaster>();
public ActionForward prepareList(ActionMapping mapping,
ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
try{
session=HibernateSessionFactory.getSession();
tx=session.beginTransaction();
Form2 form2form=(Form2) form;
ArrayList<BudgetheadBean> budgetheads=new ArrayList<BudgetheadBean>();
// Retrieve values from database
List <Vouchermaster> list=session.createQuery("select vm from Vouchermaster as vm").list();
// Create list with database values and strore in array
for (Iterator iter = list.iterator(); iter.hasNext();) {
detailHeadList.add((Vouchermaster)iter.next());
}
for(int i=0;i<detailHeadList.size();i++){
Vouchermaster d =detailHeadList.get(i);
if (d.getBudgethead().length()>50){
head=d.getBudgethead().substring(0, 49).toString();
}else{
head=d.getBudgethead().toString();
}
budgetheads.add(new BudgetheadBean(d.getBudgetcode(),head));
}
// set values to form no 2 from Tab "Budget"
form2form.setBudgetHeadListMain(budgetheads);
form2form.setBudgetHeadListSub(budgetheads);
target="success";
}catch(Exception e){
System.out.println("Error Occured...1");
e.printStackTrace();
target="failure";
}
return mapping.findForward(target);
}