Own Component with UIComponentBase and XPath Expression issue
haukegulich Dec 19, 2011 3:28 AMHello everyone,
I have a strange problem and I don't know if this is really a richfaces issue. Maybe somebody can help me.
What I want:
on my xhtml page I want to put an own new tag <cu:custom/>. This tag should print a svg xml structure to my page. Before printing it to the page I need to modify some styles from the svg xml.
How I did this:
In my java class which extends UIComponentBase I load via the classloader the resource file (xml file with svg structure). Then I created a dom4j document object and tried to fetch the node via xpath in order to modify the style of this node.
What is working:
If I load the resource file and pass it to the document everything is working fine !
But as soon as I call some xpath expressions like
{code}Node nodeList = document.getRootElement().selectSingleNode("//g/rect[@id='id_zustand_pumpe']");{code}
I get a strange exception on this line. Even though I can't find any informations about my own class in the stacktrace I figured out the position of the problem with some logging information and if I remove this line, everything works again. The line "---------*****************************" isn't showing in my log file (see sources below)
This is my exception:
{color:#f00}
09:11:45,460 ERROR [[Faces Servlet] | ] | Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException: CDATA tags may not nest |
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:630) [jsf-impl-2.1.3-b02-jbossorg-2.jar:2.1.3-SNAPSHOT] | |
at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:172) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1] | |
at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:342) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1] | |
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200) [jsf-impl-2.1.3-b02-jbossorg-2.jar:2.1.3-SNAPSHOT] | |
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:123) [jsf-impl-2.1.3-b02-jbossorg-2.jar:2.1.3-SNAPSHOT] | |
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [jsf-impl-2.1.3-b02-jbossorg-2.jar:2.1.3-SNAPSHOT] | |
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.3-b02-jbossorg-2.jar:2.1.3-SNAPSHOT] | |
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1] | |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.richfaces.webapp.PushFilter.doFilter(PushFilter.java:144) [richfaces-core-impl-4.0.0.Final.jar:] | |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final] | |
at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final] | |
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final] | |
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final] | |
at java.lang.Thread.run(Thread.java:619) [:1.6.0_21] |
{color}
Here are my classes and or files I am using:
MyCustom.java
{code}
package de.hauke.client.playground;
import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
@FacesComponent(value = "mycustom")
public class MyCustom extends UIComponentBase {
@Override
public String getFamily() {
return "custom";
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
try{
System.out.println("---------------------------------------------------");
SAXReader reader = new SAXReader();
Document document = reader.read(this.getClass().getClassLoader().getResourceAsStream("/rules.xml"));
Node nodeList = document.getRootElement().selectSingleNode("//g/rect[@id='id_zustand_pumpe']");
System.out.println("Nodelist : " + nodeList.getName());
System.out.println("---------*****************************");
ResponseWriter responseWriter = context.getResponseWriter();
responseWriter.startElement("div", null);
responseWriter.write(document.asXML());
responseWriter.endElement("div");
} catch(Exception ex) {
System.out.println(ExceptionUtils.getFullStackTrace(ex));
}
}
}{code}
rules.xml
{code:xml}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="750"
height="600"
id="svg3413"
version="1.1">
<defs
id="defs3415">
</defs>
<metadata
id="metadata3418">
</metadata>
<g
id="layer1"
transform="translate(0,-452.36218)">
<rect
style="fill:#dcdcdc;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;opacity:1"
id="id_zustand_pumpe"
width="80.019684"
height="24.019682"
x="335.49017"
y="456.60474"
rx="2.0004921"
ry="1.9215745"
/>
</g>
</svg>
{code}