[ http://issues.apache.org/jira/browse/IBATIS-281?page=comments#action_12412033 ]
Christian Poitras commented on IBATIS-281: ------------------------------------------ I think I was not clear in my other comment. The comment was related to my patch. The patch I proposed has some major programming problems and I sent them to give a starting point. The first problem is the duplicate of the added code in classes ConditonalTagHandler and IterateTagHandler. The added code part should be removed from these classes and put in one simple class. I suggest the IterateContext that could handle the replacing of values in another tag property value. The TagHandlers could then call "parentIterateContextInstance.processProperty(currentTag.getProperty());" when there is a "[]" in the property. The code in IterateContext would be almost he same as my code, since my code will not work in this specific example. <statement> <iterate property="list"> <iterate property="list[3].list"> </iterate> </iterate> </statement> The reason is that my code will try add the index value of the first iterate tag even if the value is specified (here, the value is 3). This will generate an exception. To correct the problem, we only need to check if the caracter after the "[" is a "]". If this is not the case, skip the current iterate context and call it's parent "processProperty" method if there is still an unprocessed "[" in the property. We also need a getParent() method in IterateContext that will return it's parent IterateContext. I suggest to add this king of code for the processProperty() method. public method processProperty(String tagPropety) { int index = lastIndexOf("["); int propertyIndex = lastIndexOf(this.getProperty); if () { } The same problem applies to ConditionalTagHandler. Jeff, I'm sorry I didn't see the problem #3 you are talking about. Can you show me an exemple where this kind of bug happens? I may have already a part of the solution for the problem. Maybe the problem can be solved by adding this code to ConditionalTagHandler doStartFragment() method. // Increase index if the first tag is another iterate. IterateContext itCtx = ctx.peekIterateContext(); if(null != itCtx && itCtx.isAllowNext()){ itCtx.next(); itCtx.setAllowNext(false); if(!itCtx.hasNext()) { itCtx.setFinal(true); } } The DynamicSql class could also make a call to "iterateContext.processProperty();" to replace the body content replacing my code. These changes will make the patch easier to maintain for future development. For problem #2, applying these changes could result in correcting the bug... I believe my patch needs to have > Nested iterate tags does not work > --------------------------------- > > Key: IBATIS-281 > URL: http://issues.apache.org/jira/browse/IBATIS-281 > Project: iBatis for Java > Type: Bug > Components: SQL Maps > Versions: 2.1.7 > Reporter: Christian Poitras > Assignee: Jeff Butler > Attachments: ConditionalTagHandler.java, DynamicSql.java, > IterateTagHandler.java > > No nested iterate tags work. The second iterate tag is not supported and > produces the following error. > java.lang.NumberFormatException: For input string: "" > at > java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) > at java.lang.Integer.parseInt(Integer.java:489) > at java.lang.Integer.parseInt(Integer.java:518) > at com.ibatis.common.beans.BaseProbe.getIndexedProperty(BaseProbe.java:51) > at > com.ibatis.common.beans.ComplexBeanProbe.getProperty(ComplexBeanProbe.java:297) > at > com.ibatis.common.beans.ComplexBeanProbe.getObject(ComplexBeanProbe.java:188) > at com.ibatis.common.beans.GenericProbe.getObject(GenericProbe.java:76) > at > com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.IterateTagHandler.doStartFragment(IterateTagHandler.java:34) > at > com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:157) > at > com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:160) > at > com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:99) > at > com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.process(DynamicSql.java:79) > at > com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.getParameterMap(DynamicSql.java:61) > at > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:156) > at > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123) > at > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610) > at > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584) > at > com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101) > at > com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78) > at > com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForList(SqlMapDaoTemplate.java:203) > at > ca.qc.ircm.lana.persistence.sqlmapdao.SpotSqlMapDao.getSpotsInter(SpotSqlMapDao.java:159) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java:72) > at $Proxy14.getSpotsInter(Unknown Source) > at > ca.qc.ircm.lana.service.InterpretationService.getSpotsInter(InterpretationService.java:82) > at TEST.testInterpretation.main(testInterpretation.java:111) > It seems the second iterate tag cannot have a property of this type. > <iterate property="list" > > <iterate property="list[].list"> > <iterate> > </iterate> > On the nested iterate, SQL Maps does not add the number in attribute property > "list[].list" and tries to call a getter for parameterClass.getList[]() and > this is not allowed and produces the error. > This could be prevented in the IterateTagHandler class (doStartFragment > method) by adding code that replaces "[]" in the property attribute by values > of IterateContext that are parents of the current tag (for multiple nested > iterate). > Other code would need to be updated since using a property in the second list > also causes SQL Map to crash even it IterateTagHandler is patched. > <iterate property="list" > > <iterate property="list[].list"> > #list[].list[].someProperty# > <iterate> > </iterate> > I produced a patch that can correct the problem. I will include it in a > future message. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira