• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Error:No valid collection specified for size tag

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic