logic:iterate problem: NullPointerException
Hi to all. I have a problem with a logic:iterate tag. I'm using Struts 1.3. I have to populate a select with data read from db (by invoking the first Action). When a select option is selected in the jsp, I have to invoke a second Action (on the same jsp page) which has to perform some operations and remember the previous selected option (in the select). I show you my source code for semplicity. Here is my ActionForm. *** CreazioneProfiloUtenteForm.java *** public class CreazioneProfiloUtenteForm extends ActionForm { private String sport; public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) { return null; } public void reset(ActionMapping mapping, HttpServletRequest request) { } public String getSport() { return sport; } public void setSport(String sport) { this.sport = sport; } } First, the ToCreazioneProfiloUtenteAction action is invoked. This action reads data from db and insert them in the ArrayList 'listaSport'; at the end, this ArrayList is setted in the request. *** ToCreazioneProfiloUtenteAction.java *** public class ToCreazioneProfiloUtenteAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) { ... ... ArrayList listaSport = null; listaSport = new ArrayList(); listaSport.add(new org.apache.struts.util.LabelValueBean(defaultOptionSelect,)); while(db.getResultSet().next()) listaSport.add(new org.apache.struts.util.LabelValueBean(db.getResultSet().getString(nomeSport),db.getResultSet().getString(idSport))); request.setAttribute(listaSport, listaSport); ... ... } } Then creazioneProfiloUtente.jsp is invoked. I have a select 'sport' that reads the collections in the ArrayList 'listaSport'. Then, I have to store in hidden fields the values of the 'listaSport' arraylist in order to avoid, in the second Action, to re-access to db to read the same values. In order to do so, I use logic:iterate but I have problems with it. I confirm that if I delete from source code the tag logic:iterate, all works well. ** creazioneProfiloUtente.jsp ** ... ... html:select property=sport styleId=sport o_nchange=javascript:submitForm('creazioneProfiloUtenteForm','caricamentoRuoliAttributiSport.do') html:optionsCollection name=listaSport / /html:select logic:iterate id=sport name=listaSport html:hidden name=sport property=label indexed=true / html:hidden name=sport property=value indexed=true / /logic:iterate ... ... This is the second Action, which should be invoked when a select option is selected by user. Unfortunately, this Action is never accessed because I got a java NullPointerException before. * CaricamentoRuoliAttributiSportAction.java * public class CaricamentoRuoliAttributiSportAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) { System.out.println(X); } } * EXCEPTION * GRAVE: Servlet.service() for servlet action threw exception java.lang.NullPointerException at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:427) at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:340) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:684) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715) at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:884) at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:467) at org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50) at
logic:iterate - problem
Hello! I've got a problem to get a value within a logic:iterate construction (foo is an ArrayList Object): logic:iterate name=foo id=object html:textarea ... rows='bean:write name=object property=rows/' / /logic:iterate This does not work. How must it been written to address the method getRows() in the object, which has been defined by id in logic:iterate? Kind regards, Andreas Hartmann Jetzt Handykosten senken mit klarmobil - 14 Ct./Min.! Hier klicken http://produkte.shopping.freenet.de/handy_voip_isdn/klarmobil/index.html?pid=730025 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: logic:iterate - problem
Try following tag... html:textarea ... rows='%= ((YourObject)pageContext.getAttribute(object)).getRows()%' / On 7/10/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello! I've got a problem to get a value within a logic:iterate construction (foo is an ArrayList Object): logic:iterate name=foo id=object html:textarea ... rows='bean:write name=object property=rows/' / /logic:iterate This does not work. How must it been written to address the method getRows() in the object, which has been defined by id in logic:iterate? Kind regards, Andreas Hartmann Jetzt Handykosten senken mit klarmobil - 14 Ct./Min.! Hier klicken http://produkte.shopping.freenet.de/handy_voip_isdn/klarmobil/index.html?pid=730025 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Yoge, AdventNet, Inc. 925-965-6528 [EMAIL PROTECTED] site24x7.com
Re: logic:iterate - problem
Another way to do it (with a little bit less java) is: logic:iterate name=foo id=object bean:define id=rows name=object property=rows / html:textarea ... rows='%=rows%' / /logic:iterate [EMAIL PROTECTED] wrote: Hello! I've got a problem to get a value within a logic:iterate construction (foo is an ArrayList Object): logic:iterate name=foo id=object html:textarea ... rows='bean:write name=object property=rows/' / /logic:iterate This does not work. How must it been written to address the method getRows() in the object, which has been defined by id in logic:iterate? Kind regards, Andreas Hartmann Jetzt Handykosten senken mit klarmobil - 14 Ct./Min.! Hier klicken http://produkte.shopping.freenet.de/handy_voip_isdn/klarmobil/index.html?pid=730025 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Chad S. Lauritsen Ecommerce Enterprise Developer The Sherwin-Williams Company 216-566-2166 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: logic:iterate - problem
Hello Chad, hello Yoge, thanks for your hints! meanwhile, I could find a third solution: logic:iterate name=foo id=object type=my.url.classname html:textarea ... rows=%= object.getRows() % / /logic:iterate Another solution should be to use EL: html:textarea ... rows=${object.rows}/ But this solution doesn't work for me (the string ${object.rows} appears unchanged after rows=) , though I'm using tomcat 5.5 and struts 1.2.9.. May be, it should be written as: %@ taglib uri=/WEB-INF/struts-html-el.tld prefix=html-el % %@ taglib uri=/WEB-INF/struts-logic-el.tld prefix=logic-el % logic-el:iterate name=foo id=object type=my.url.classname html-el:textarea ... rows=${object.rows} / /logic-el:iterate (from: http://entwickler-forum.de/showthread.php?t=33417 ) Kind regards, Andreas Hartmann Chad S. Lauritsen wrote: Another way to do it (with a little bit less java) is: logic:iterate name=foo id=object bean:define id=rows name=object property=rows / html:textarea ... rows='%=rows%' / /logic:iterate [EMAIL PROTECTED] wrote: Hello! I've got a problem to get a value within a logic:iterate construction (foo is an ArrayList Object): logic:iterate name=foo id=object html:textarea ... rows='bean:write name=object property=rows/' / /logic:iterate This does not work. How must it been written to address the method getRows() in the object, which has been defined by id in logic:iterate? Kind regards, Andreas Hartmann - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
logic:iterate problem...
Hi all... I get this exception trying to render options with logic iterate tag... javax.servlet.jsp.JspException: Cannot create iterator for this collection My action just get a List form a Srevice layer and store it in session scope under Globales.AreaPersonal.MODULOS_KEY. logic:iterate id=modulo collection='%=Globales.AreaPersonal.MODULOS_KEY%' option value='%=((Contenible)modulo).getId()%' %=((Contenible)modulo).getNombre()+ - + ((Contenible)modulo).getTitulo()% /option /logic:iterate i wish someone help me... thanks! Lucas __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
Re: logic:iterate problem...
I think your List reference is probably null. Also, have you looked at html:options and html:optionsCollection? Erik Lucas Bern wrote: Hi all... I get this exception trying to render options with logic iterate tag... javax.servlet.jsp.JspException: Cannot create iterator for this collection My action just get a List form a Srevice layer and store it in session scope under Globales.AreaPersonal.MODULOS_KEY. logic:iterate id=modulo collection='%=Globales.AreaPersonal.MODULOS_KEY%' option value='%=((Contenible)modulo).getId()%' %=((Contenible)modulo).getNombre()+ - + ((Contenible)modulo).getTitulo()% /option /logic:iterate i wish someone help me... thanks! Lucas __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: logic:iterate problem...
I would like to get a null pointer exception or a can not set bean to null when my list is null... I use to solve this kind of problem with html:options and html:optionsCollection but what i have to do in this page is very complex for this tags... thanks for your answer Erik Lucas Erik Weber [EMAIL PROTECTED] wrote: I think your List reference is probably null. Also, have you looked at html:options and html:optionsCollection? Erik Lucas Bern wrote: Hi all... I get this exception trying to render options with logic iterate tag... javax.servlet.jsp.JspException: Cannot create iterator for this collection My action just get a List form a Srevice layer and store it in session scope under Globales.AreaPersonal.MODULOS_KEY. i wish someone help me... thanks! Lucas __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - 250MB gratis, Antivirus y Antispam Correo Yahoo!, el mejor correo web del mundo Abrí tu cuenta aquí
Re: logic:iterate problem...
Hmm I didn't even notice that. However, this is the section of code that throws that Exception (from 1.2.4 src): /** * Construct an iterator for the specified collection, and begin * looping through the body once per element. * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { // Acquire the collection we are going to iterate over Object collection = this.collection; if (collection == null) { collection = TagUtils.getInstance().lookup(pageContext, name, property, scope); } if (collection == null) { JspException e = new JspException(messages.getMessage(iterate.collection)); TagUtils.getInstance().saveException(pageContext, e); throw e; } So I'm not sure. Erik Michael Jouravlev wrote: Looks like you are trying to iterate over string. How about this: logic:iterate id=modulo collection='%=(List) session.getAttribute(Globales.AreaPersonal.MODULOS_KEY)%' Michael. On 4/21/05, Lucas Bern [EMAIL PROTECTED] wrote: Hi all... I get this exception trying to render options with logic iterate tag... javax.servlet.jsp.JspException: Cannot create iterator for this collection My action just get a List form a Srevice layer and store it in session scope under Globales.AreaPersonal.MODULOS_KEY. logic:iterate id=modulo collection='%=Globales.AreaPersonal.MODULOS_KEY%' option value='%=((Contenible)modulo).getId()%' %=((Contenible)modulo).getNombre()+ - + ((Contenible)modulo).getTitulo()% /option /logic:iterate i wish someone help me... thanks! Lucas __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: logic:iterate problem...
From http://struts.apache.org/userGuide/struts-logic.html#iterate: collection: A runtime expression that evaluates to a collection %=Globales.AreaPersonal.MODULOS_KEY% probably evaluates to a String. What you need is name='%=Globales.AreaPersonal.MODULOS_KEY%' On 4/21/05, Lucas Bern [EMAIL PROTECTED] wrote: My action just get a List form a Srevice layer and store it in session scope under Globales.AreaPersonal.MODULOS_KEY. logic:iterate id=modulo collection='%=Globales.AreaPersonal.MODULOS_KEY%' - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: logic:iterate problem...
Great! it works fine... thanks Jeff and Erik. Lucas Jeff Beal [EMAIL PROTECTED] wrote: From http://struts.apache.org/userGuide/struts-logic.html#iterate: collection: A runtime expression that evaluates to a collection probably evaluates to a String. What you need is name='' On 4/21/05, Lucas Bern wrote: My action just get a List form a Srevice layer and store it in session scope under Globales.AreaPersonal.MODULOS_KEY. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - 250MB gratis, Antivirus y Antispam Correo Yahoo!, el mejor correo web del mundo Abrí tu cuenta aquí
R: Logic:Iterate Problem
Hi, you can use the JSTL1.1 (or 1.0 as you want) in the following way: %@ taglib uri=http://java.sun.com/jsp/jstl/core; prefix=c % table c:forEach items=${requestScope.pageRecords} var=row trc:out value=${row.Id}//tr /c:forEach /table you can use pageScope, requestScope, sessionScope or applicationScope depending on the pageRecords is stored. -Messaggio originale- Da: Eddie Yan [mailto:[EMAIL PROTECTED] Inviato: mercoledì 23 giugno 2004 18.06 A: [EMAIL PROTECTED] Oggetto: Logic:Iterate Problem Hi guys, Say I have a JSP as follows: table tr % Iterator iter = pageRecords.iterator(); while(iter.hasNext()) { UserDetail detail = (UserDetail)iter.next(); % td %= detail.getId() % /td % } % /tr /table pageRecords is a Collection of UserDetail object. UserDetail is my data transfer object. I can manage to get the expected result of detail.getId() How can I represent the above code in logic:iterate tags ? The following code doesn't work. table tr logic:iterate id=myID collection=pageRecords property=UserDetail td bean:write name=myID property=id / /td /logic:iterate /tr /table I got JSP Exception: Cannot create iterator for this collection - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Logic:Iterate Problem
Assuming you have a scoped Collection named pageRecords: Struts tags: logic:iterate id=myID name=pageRecords td bean:write name=myID property=id / /td /logic:iterate JSTL: c:forEach var=user items=${pageRecords} c:out value=${user.id}/ /c:forEach robert -Original Message- From: Eddie Yan [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 23, 2004 12:06 PM To: [EMAIL PROTECTED] Subject: Logic:Iterate Problem Hi guys, Say I have a JSP as follows: table tr % Iterator iter = pageRecords.iterator(); while(iter.hasNext()) { UserDetail detail = (UserDetail)iter.next(); % td %= detail.getId() % /td % } % /tr /table pageRecords is a Collection of UserDetail object. UserDetail is my data transfer object. I can manage to get the expected result of detail.getId() How can I represent the above code in logic:iterate tags ? The following code doesn't work. table tr logic:iterate id=myID collection=pageRecords property=UserDetail td bean:write name=myID property=id / /td /logic:iterate /tr /table I got JSP Exception: Cannot create iterator for this collection - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
R: Logic:Iterate Problem
Hi, you can use the JSTL1.1 (or 1.0 as you want) in the following way: %@ taglib uri=http://java.sun.com/jsp/jstl/core; prefix=c % table c:forEach items=${requestScope.pageRecords} var=row trc:out value=${row.Id}//tr /c:forEach /table you can use pageScope, requestScope, sessionScope or applicationScope depending on the pageRecords is stored. BR /Amleto -Messaggio originale- Da: Eddie Yan [mailto:[EMAIL PROTECTED] Inviato: mercoledì 23 giugno 2004 18.06 A: [EMAIL PROTECTED] Oggetto: Logic:Iterate Problem Hi guys, Say I have a JSP as follows: table tr % Iterator iter = pageRecords.iterator(); while(iter.hasNext()) { UserDetail detail = (UserDetail)iter.next(); % td %= detail.getId() % /td % } % /tr /table pageRecords is a Collection of UserDetail object. UserDetail is my data transfer object. I can manage to get the expected result of detail.getId() How can I represent the above code in logic:iterate tags ? The following code doesn't work. table tr logic:iterate id=myID collection=pageRecords property=UserDetail td bean:write name=myID property=id / /td /logic:iterate /tr /table I got JSP Exception: Cannot create iterator for this collection - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]