Author
Error:No valid collection specified for size tag
divya sharma
Ranch Hand
Joined: Jan 25, 2007
Posts: 87
posted Sep 04, 2007 09:48:00
0
Hello, I recived this error when I am searching employee list here is the code for search.jsp <%@ page language="java" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <html> <head> <title> Abc,Inc Human Resource Portal</title> </head> <body> <Font size="+1">Abc,Inc Human Resource Portal </Font> <hr width="100%"> <html:errors/> <html:form action="/search"> <table> <tr> <td align="right"> <bean:message key ="label.search.name"/>:</td> <td><html:text property="name"/></td> <tr> <td align="right"> <bean:message key ="label.search.ssNum"/>:</td> <td><html:text property="ssNum"/>(xxx-xx-xxx)</td> </tr> <tr> <td> <html:submit/></td> </tr> </table> </html:form> <logic resent name="searchForm" property="results"> <hr width="100%"> <bean:size id="size" name="searchForm" property="results"/> <logic:equal name="size" value="0"> <center> <font color="red"><b> No Employee found</b></font></center> </logic:equal> <logic:greaterThan name="size" value="0" > <table border="1"> <tr> <th> Name</th> <th> SSN</th> </tr> <logic:iterate id ="result" name ="searchForm" property="results"> <tr> <td> <bean:write name="result" property="name"/> </td> <td><bean:write name="result" property="ssNum"/> </td> </tr> </logic:iterate> </table> </logic:greaterThan> </logic resent> </body> </html> SearchForm.java package com.jamesholmes.minihr; import java.util.List ; import javax.servlet.http.HttpServletRequest ; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class SearchForm extends ActionForm { private String name =null; private String ssNum =null; private List results =null; public void setName(String name) { this.name = name; } public String getName() { return name; } public void setSsNum(String ssNum) { this.ssNum = ssNum; } public String getSsNum() { return ssNum; } public void setResults(List results) { this.results = results; } public String getResults() { return ssNum; } public void reset(ActionMapping mapping,HttpServletRequest request) { name=null; ssNum=null; results=null; } //validate data public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors error = new ActionErrors(); boolean nameEntered = false; boolean ssNumEntered = false; if(name!=null && name.length()>0) { nameEntered = true; } if(ssNum!=null && ssNum.length()>0) { ssNumEntered = true; } if(!nameEntered && !ssNumEntered) { error.add(null, new ActionError("error.search.critria.missing")); } if(nameEntered && !isValidSsNum(ssNum.trim())){ error.add("ssNum", new ActionError("error.search.ssNum.invaild")); } return error; } public static boolean isValidSsNum(String ssNum) { if(ssNum.length()<11){ return false; } for(int i=0;i<11;i++) { if(i==3||i==6){ if(ssNum.charAt(i)!='-'){ return false; } }else if ("0123456789".indexOf(ssNum.charAt(i))== -1){ return false; } } return true; } } Thanks
Divya
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
I'm not really sure what's causing your error message, but I'd recommend you abandon use of the logic resent and bean:size tags and simply use logic:empty and logic:notEmpty. This will simplify your logic, as it checks for both presence of the collection and a size of greater than zero.
Merrill
Consultant, Sima Solutions
subject: Error:No valid collection specified for size tag