G
gmjing
i use struts collection,it work fine.but it happen errors when i put
checkbox in every row.the errors like this:
javax.servlet.ServletException: Getter for property ids[0] threw
exception: java.lang.NullPointerException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContext-Impl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextIm-pl.java:758)
org.apache.jsp.queryusera_jsp._jspService(queryusera_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:-324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1-069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProce-ssor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279-)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
//jsp file
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@page import="com.yourcompany.struts.form.*,java.util.ArrayList"%>
<html>
<head>
<title>JSP for UserForm form </title>
<layout:skin/>
</head>
<body>
<html:form action="/user">
<html:hidden property="oper" value="delUser"/>
<html:submit/><html:cancel/>
<layoutager maxPageItems="20">
<layout:collection title="aaassss"
name="results"
styleClass="FORM" styleClass2="FORM2"
selectName="ids" selectProperty="name" selectType="checkbox">
<layout:collectionItem title="a" property="name"
sortable="true"/>
<layout:collectionItem title="b" property="dep"
sortable="true"/>
<layout:collectionItem title="c" property="age"
sortable="true"/>
<layout:collectionItem title="d" property="desc"
sortable="true"/>
</layout:collection>
</layoutager>
</html:form>
</body>
</html>
//struts---Form Class
public class UserForm extends ActionForm {
private String[] ids;
private String age;
private String dep;
private String name;
private String desc;
public String[]getIds() {
return ids;
}
public void setIds(String[]ids) {
this.ids = ids;
}
public String getIds(int index) {
return this.ids[index];
}
public void setIds(int index, String id) {
this.ids[index] = id;
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
return null;
}
public void reset(ActionMapping mapping, HttpServletRequest
request) {
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getDep() {
return dep;
}
public void setDep(String dep) {
this.dep = dep;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
//struts---Action Class
public class UserAction extends DispatchAction {
public ActionForward qryUser(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
ArrayList l_users = new ArrayList ();
for(int i=0;i<300;i++)
{
UserForm a = new UserForm();
a.setAge("12"+i);
a.setDep("aaa"+i);
a.setDesc("aaaaaaa"+i);
a.setName("aaaa"+i);
l_users.add(a);
}
request.setAttribute("results", l_users);
return mapping.findForward("qrysuc");
}
checkbox in every row.the errors like this:
javax.servlet.ServletException: Getter for property ids[0] threw
exception: java.lang.NullPointerException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContext-Impl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextIm-pl.java:758)
org.apache.jsp.queryusera_jsp._jspService(queryusera_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:-324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1-069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProce-ssor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279-)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
//jsp file
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@page import="com.yourcompany.struts.form.*,java.util.ArrayList"%>
<html>
<head>
<title>JSP for UserForm form </title>
<layout:skin/>
</head>
<body>
<html:form action="/user">
<html:hidden property="oper" value="delUser"/>
<html:submit/><html:cancel/>
<layoutager maxPageItems="20">
<layout:collection title="aaassss"
name="results"
styleClass="FORM" styleClass2="FORM2"
selectName="ids" selectProperty="name" selectType="checkbox">
<layout:collectionItem title="a" property="name"
sortable="true"/>
<layout:collectionItem title="b" property="dep"
sortable="true"/>
<layout:collectionItem title="c" property="age"
sortable="true"/>
<layout:collectionItem title="d" property="desc"
sortable="true"/>
</layout:collection>
</layoutager>
</html:form>
</body>
</html>
//struts---Form Class
public class UserForm extends ActionForm {
private String[] ids;
private String age;
private String dep;
private String name;
private String desc;
public String[]getIds() {
return ids;
}
public void setIds(String[]ids) {
this.ids = ids;
}
public String getIds(int index) {
return this.ids[index];
}
public void setIds(int index, String id) {
this.ids[index] = id;
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
return null;
}
public void reset(ActionMapping mapping, HttpServletRequest
request) {
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getDep() {
return dep;
}
public void setDep(String dep) {
this.dep = dep;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
//struts---Action Class
public class UserAction extends DispatchAction {
public ActionForward qryUser(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
ArrayList l_users = new ArrayList ();
for(int i=0;i<300;i++)
{
UserForm a = new UserForm();
a.setAge("12"+i);
a.setDep("aaa"+i);
a.setDesc("aaaaaaa"+i);
a.setName("aaaa"+i);
l_users.add(a);
}
request.setAttribute("results", l_users);
return mapping.findForward("qrysuc");
}