Weblogic and JSP recursive tags

I have a Weblogic 10.3.3 installation and it seems to be having problems with recursive JSP tags. On the Internet, I found that some other people are experiencing the same problems ( here and here ), but there are no solutions. Some people believe that it is fixed in Weblogic 12 or works in 9, but I can’t confirm this.

Application built using Spring / Spring Roo / Apache Tiles / jspx. The displayed model class looks something like this:

public class Programme { private String name; private final List<Programme> programmes = new ArrayList<Programme>(); ...(getter/setter)... } 

Then I have tagx like this:

 <jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:coursedataimport="urn:jsptagdir:/WEB-INF/tags/coursedataimport" version="2.0"> <jsp:output omit-xml-declaration="yes" /> <jsp:directive.attribute name="programme" type="package.Programme" required="true" rtexprvalue="true" /> <c:out value="${programme.name}" /> <ul> <c:forEach var="p" items="${programme.programmes}"> <li><coursedataimport:programme programme="${p}" /></li> </c:forEach> </ul> </jsp:root> 

This does not work. When you request a page, the application container seems to crash (maybe a stack overflow, but I cannot find it in the logs), and the application context reloads. In Tomcat 7, it works great.

The exception shown is something like this, but I'm not sure if this is related (as it talks about the error):

[ServletContext @ 483389576 [application: app-ear-0 module: application path: / CONTEXT version specification: 2.5]] A problem occurred while serving the error page. org.springframework.web.util.NestedServletException: request processing failed; The nested exception is java.lang.ClassCastException: org.apache.tiles.ArrayStack at org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:894) in org.springframework.web.servlet.FrameworkServlet.doGet Framework .java: 779) in Level Above: Level Above: ...

Has anyone experienced these problems before or is anyone aware of a fix? Any advice on how to debug this, or how to bypass a recursive tag (since I want to display a tree, this is a bit of a challenge). Thanks in advance.

+6
source share
1 answer

I do not know how to fix the tag engine. But my answer is a workaround on how to rule out recursion altogether. The idea that any recursion can be reduced by using java.util.Stack. You can then create an indentation field that indicates how many spaces should be reserved to display the tree structure

Java code to indent a linear list:

 class FormattedProgramme{ Programme programme; int indent; } ... java.util.List<FormattedProgramme> result = new ArrayList<FormattedProgramme>(); java.util.Stack<FormattedProgramme> programmeStack = new java.util.Stack<FormattedProgramme>(); //you should know how to resolve root bean 'programme' programmeStack.push(new FormattedProgramme(programme, 0/*indent=0*/)); while(!programmeStack.empty()){ FormattedProgramme parent = programmeStack.pop(); result.add(parent); for(Programme child:parent.programme.programmes ){ //create child item with indentation + 1 //may be you need keep order of items - then reverse this loop programmeStack.push(new FormattedProgramme(child, parent.indent+1)); } } 

After that, in JSP you can put something that creates an addition (there is padding-left of the div multiplied by 10px):

 <c:forEach var="fp" items="${formatted}"> <div style='padding-left:${fp.indent * 10}px'> <c:out value="${fp.programme.name}" /> </div> </c:forEach> 
0
source

All Articles