Run over a collection within a bean with logic:iterate
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Karsten_Schramm
Posted On:   Wednesday, November 10, 2004 03:15 AM

Hi, I'm trying to iterate over an array(list) and it doesn't work. :-( from page welcome.jsp comes the following bean: /* * Created on 09.11.2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package de.isogmbh.test; import java.util.ArrayList; import java.util.Collection; 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.ActionMa   More>>

Hi,



I'm trying to iterate over an array(list) and it doesn't work. :-(



from page welcome.jsp comes the following bean:



			
/*
* Created on 09.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package de.isogmbh.test;

import java.util.ArrayList;
import java.util.Collection;

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;


/**
* @author srm
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class testActionForm extends ActionForm {
/* (non-Javadoc)
* @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
*/
private ArrayList Feld = new ArrayList();
private String Furzkopp;

/**
* @return Returns the feld.
*/


public ArrayList getFeld()
{
return Feld;
}

public String getFeld(int index) {
System.out.println("getFeld index");
if (Feld.size() > index)
{
return (String)Feld.get(index);
}
else
{
return "";
}
}

/**
* @param feld The feld to set.
*/

public void setFeld(int index, String feld) {
System.out.println("setFeld index " + index);
while(Feld.size() <= index)
{
Feld.add("");
}
System.out.println("setFeld index " + index);
Feld.set(index, feld);
}

/**
* @return Returns the furzkopp.
*/
public String getFurzkopp() {
return Furzkopp;
}
/**
* @param furzkopp The furzkopp to set.
*/
public void setFurzkopp(String furzkopp) {
/* int indexbound = Integer.valueOf(furzkopp).intValue();
Feld = new String[indexbound];
Furzkopp = furzkopp;*/
}

public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
// TODO Auto-generated method stub
ActionErrors actionErrors = new ActionErrors();

for(int i = 0; i < Feld.size(); i++)
{
try
{
int j;

j = Integer.parseInt((String)Feld.get(i));
}
catch (Exception Ex)
{
actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError("test.test", new Integer(i + 1)));
}
}
return actionErrors;
}

}




The ActionClass is as follows:



			
/*
* Created on 09.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package de.isogmbh.test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
* @author srm
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class testAction extends Action {

/* (non-Javadoc)
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward execute(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub

arg2.setAttribute("hoppelmoppel",arg1);
return arg0.findForward("success");
}
}




And the new page is



			
[%@ taglib uri="/tags/struts-bean" prefix="bean" %]
[%@ taglib uri="/tags/struts-html" prefix="html" %]
[%@ taglib uri="/tags/struts-logic" prefix="logic" %]

[logic:present name="hoppelmoppel"]

[bean:define id="hm" name="hoppelmoppel" type="de.isogmbh.test.testActionForm" /]
[%
java.util.ArrayList myAL = hm.getFeld();
out.println((String)myAL.get(0));
%]
[br]
[logic:iterate id="hm_it" name="hoppelmoppel" property="feld" type="java.util.ArrayList"]
[bean:write name="hm_it" property="feld"/]
[/logic]

[/logic]

[logic:notPresent name="hoppelmoppel"]
testForm nicht daaaaaa!
[/logic]




The code within [% and %] works fine, but I don'tz get the iterate code work.



The error is


javax.servlet.ServletException: Cannot create iterator for this collection



Can anybody help?    <<Less
About | Sitemap | Contact