我使用装饰器类在显示表中添加了复选框 如下面的代码段所示
public String getStatus()
{
DisplayLogTimeForm dltf =(DisplayLogTimeForm)getCurrentRowObject();
String ret="";
String status= dltf.getStatus();
String date= dltf.getSET_DATE();
//System.out.println("Decorator..." + date);
if(status.equals("notpresent"))
{
System.out.println("Decorator..." + date);
ret="<input type='checkbox' size='10' id = 'statusp"+i+"' name = 'statusp' property = 'status' value='"+date+"' onclick='changeCounter(this.id);' /><input type='hidden' name='checkedBox' value='"+i+"' />";
i++;
System.out.println("id.." + ret);
System.out.println("id.." + i);
return ret;
}
else
{
return null;
}
我想获取动作类中复选框的值。请建议
答案 0 :(得分:0)
我也遇到过这个问题,目前在我的项目中使用过。 希望它对你有用。
Approve.jsp
============
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<jsp:scriptlet>
<![CDATA[
org.displaytag.decorator.CheckboxTableDecorator decorator = new org.displaytag.decorator.CheckboxTableDecorator();
decorator.setId("form_no");
decorator.setFieldName("_chk");
request.setAttribute("checkboxDecorator", decorator);
]]>
</jsp:scriptlet>
<script type="text/javascript">
function Fnc_FormAction(action)
{
document.forms[0].action="<%=request.getContextPath()%>/approve.do?reqCode="+action;
document.forms[0].submit();
}
function checkbox(form,form_no)
{
if(form.checked)
{
form.value= form_no;
}
}
</script>
<html:form method="POST" action="/approve.do" styleClass="FORM" styleId="form" style="form">
<display:table name="result" export="false" class="displaytag"
requestURI="/approve.do?reqCode=approve" id="ReportTable"
uid="ReportTable" cellpadding="0" style="width:1200px"
decorator="checkboxDecorator" excludedParams="updateList">
<display:column title="Check To Approve">
<input name="form_no" type="hidden" value="<%=((Approval)ReportTable).getForm_no() %>" />
<input type="checkbox" name="chk" value="<%=((Approval)ReportTable).getForm_no() %>" onclick="checkbox(this,<%=((Approval)ReportTable).getForm_no() %>)">
</display:column>
<input type="button" name="Approve" id="Approval" value=" Approve " onclick="Fnc_FormAction('approveByRoles')"/>
</display:table>
ApproveActionForm
==================
private int chk[];
/**
* @return the chk
*/
public int[] getChk() {
return chk;
}
/**
* @param chk the chk to set
*/
public void setChk(int[] chk) {
this.chk = chk;
}
ApproveAction.java
==================
public ActionForward approveByRoles(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws STException
{
ApproveActionForm aprForm=(ApproveActionForm)form;
if(aprForm.getChk()!=null)
{
int chks[] = aprForm.getChk();
int updateFormNo = 0;
for(int i=0;i<chks.length;i++)
{
updateFormNo = chks[i];
System.out.println("Updated Form Number is = "+ updateFormNo);
}
}
}