displaytag テーブルのすべての行を同じ値で取得します。つまり、すべての行で同じ値を表示します (つまり、最後の行の値)。
以下は、formbean で値を設定する Action クラスのスニペットです。
public class FormIdSearch extends Action {
ResourceBundle rsBundle = ResourceBundle.getBundle("com.mindcraft.resources.ApplicationResource");
Collection formbeanCol = new ArrayList();
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Collection a = new ArrayList();
FormBean formbean = (FormBean)form;
ActionForward forward = new ActionForward();
ActionMessages message = new ActionMessages();
CMBConnection connection=new CMBConnection();
HRMSUtill hrms = new HRMSUtill();
IngUtill ing = new IngUtill();
AppUtill au = new AppUtill();
try{
String polNo=formbean.getPolicyNo();
String appN=(String)request.getAttribute("appno");
System.out.println("Application No.1" + appN);
String applnNo=formbean.getAppno();
System.out.println("Application No.2" + applnNo);
String appNo=(String)request.getParameter("appno");
System.out.println("Application No.3" + appNo);
HashMap<String, String> inpMap = new HashMap<String, String>();
CMBSearchResults srchResults = null;
CMBItem item = null;
inpMap.put(rsBundle.getString("CM_INDEXCLASS_ADVISORSLICENSING"), rsBundle.getString("CM_INDEXCLASS_ADVISORSLICENSING"));
//inpMap.put(rsBundle.getString("CM_INDEXCLASS_ADVISORSLICENSING"), rsBundle.getString("CM_INDEXCLASS_ADVISORSLICENSING"));
inpMap.put(rsBundle.getString("CM_COMMON_ADVISORCODE"), "AA5555");
inpMap.put(rsBundle.getString("CM_COLNAME_ADVISORCODE"), rsBundle.getString("CM_COLNAME_ADVISORCODE"));
inpMap.put(rsBundle.getString("CM_COMMON_APPNUMBER"), appNo);
inpMap.put(rsBundle.getString("CM_COLNAME_APPNUMBER"), rsBundle.getString("CM_COLNAME_APPNUMBER"));
String winId=(String)request.getSession().getAttribute("windowsId");
String empId = au.getEmpCodeOnWinId(winId);
System.out.println("winId===="+winId);
String ingBrCode="";
if(hrmsBrCode1.equalsIgnoreCase(ingBrCode1))
{
ServletContext servletcontext = request.getSession().getServletContext();
String cmbicmsrvsPath = servletcontext.getRealPath("WEB-INF/cmbicmsrvs.ini");
System.out.println("cmbicmsrvsPath "+cmbicmsrvsPath);
String icmsrvfilePath=servletcontext.getRealPath("WEB-INF/cmbicmsrvs.ini");
String icmmenvfilePath=servletcontext.getRealPath("WEB-INF/cmbicmenv.ini");
connection = new CMBConnection();
//CMConnectionPool cmConnect = new CMConnectionPool();
CMSearchDocuments searchDoc = new CMSearchDocuments();
CMConnectionPool.setIcmenvfile(icmmenvfilePath);
CMConnectionPool.setIcmsrvfile(icmsrvfilePath);
//System.out.println("HHHEYEEEYYEYE TRUE.........3");
connection=CMConnectionPool.getConnection();
srchResults=searchDoc.searchForDocumentsInCM(connection, inpMap);
Integer searchCount=srchResults.getCount();
System.out.println("searchCount "+searchCount);
LoggerUtil.logger.debug("searchCount "+searchCount);
HttpSession session = request.getSession(false);
session.setAttribute("searchCount",searchCount.toString());
for (int i = 0; i < searchCount; i++)
{
item = srchResults.getItem(i);
a=getDocumentMetaData(item,formbean);
String pid=item.getPidString();
request.setAttribute("pid", pid);
formbean.setPid(pid);
}
request.setAttribute("formbeanCol", a);
Object ia[] = a.toArray();
int sum = 0;
// sum the array
for(int i=0; i<ia.length; i++) {
sum += ((Integer) ia[i]).intValue();
System.out.println("Sum is: " + sum);
}
if(searchCount>0){
//for (int i = 0; i < srchResults.getCount(); i++){
item = srchResults.getItem(searchCount-1);
//getDocumentMetaData(item);
String pid = item.getPidString();
System.out.println("pid "+pid);
request.setAttribute("pid", pid);
forward=mapping.findForward("success");
}
else
{
forward=mapping.findForward("failure");
message.add("ErrorOccurred", new ActionMessage("Invalid.SearchResult"));
}
System.out.println("Search Done");
LoggerUtil.logger.debug("Search Done");
}
else
{
System.out.println("No Record Found");
LoggerUtil.logger.debug("No Record Found");
forward=mapping.findForward("failure");
message.add("ErrorOccurred", new ActionMessage("Invalid.SearchResult"));
}
saveMessages(request, message);
}
catch(Exception e){
forward=mapping.findForward("failure");
LoggerUtil.logger.debug("Exception in FormIdSearch ",e);
e.printStackTrace();
}
finally{
try{
if(connection!=null){
CMConnectionPool.freeConnection(connection);
}
}
catch(Exception e)
{
forward=mapping.findForward("failure");
LoggerUtil.logger.debug("Exception in FormIdSearch in finally block Closing CM Connection",e);
}
}
return forward;
}
public Collection getDocumentMetaData(CMBItem item,FormBean formbean)
throws CMBException, Exception
{
// Get document metadata attributes
String FormID = item.getAttrValue(0);
System.out.println(item.getAttrValue(0));
System.out.println(item.getAttrValue(1));
System.out.println(item.getAttrValue(2));
System.out.println(item.getAttrValue(3));
System.out.println(item.getAttrValue(4));
formbean.setFormID(FormID);
String MainDocument=item.getAttrValue(1);
formbean.setMainDocument(MainDocument);
String SubDocument=item.getAttrValue(2);
formbean.setSubDocument(SubDocument);
formbean.setAppNumber(item.getAttrValue(3));
formbean.setBranchCode(item.getAttrValue(4));
formbean.setAdvisor_NAME(item.getAttrValue(5));
formbean.setAdvisor_Code(item.getAttrValue(6));
formbeanCol.add(formbean);
System.out.println("formbeanCol.size() "+formbeanCol.size());
return formbeanCol;
}
}
JSP
<display:table name="formbeanCol" export="false" pagesize="20" sort="list" id="data" requestURI="" class="tablelist">
<display:column title="advisor_Code" sortable="true" property="advisor_Code"></display:column>
<display:column title="formID" sortable="true" property="formID"></display:column>
<display:column title="mainDocument" sortable="true" property="mainDocument"></display:column>
<display:column title="SubDocument" sortable="true" property="subDocument"></display:column>
<display:column title="AppNumber" sortable="true" property="appNumber"></display:column>
<display:column title="branchCode" sortable="true" property="branchCode"></display:column>
<display:column title="advisor_NAME" sortable="true" property="advisor_NAME"></display:column>
</display:table>