3 Replies Latest reply on Dec 19, 2011 5:40 AM by haukegulich

    Own Component with UIComponentBase and XPath Expression issue

    haukegulich

      Hello 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}


        • 1. Re: Own Component with UIComponentBase and XPath Expression issue
          mcmurdosound

          Hmmmm, a while ago, I've got the same error "CDATA tags may not nest" but I'm not quite sure where and under which circumstances it happend. Something tries to create the

          //<![CDATA[

          ...

          //]]>

           

          They cannot nest nor contain squences like ]]> http://en.wikipedia.org/wiki/CDATA#Nesting

           

          Can you provide an usage example of how your cu:custom component is used in a facelet? Maybe there is something, that causes a second CDATA to start within another.

          1 of 1 people found this helpful
          • 2. Re: Own Component with UIComponentBase and XPath Expression issue
            haukegulich

            Well the only thing I can post are the other files which are required. The whole project is way to huge.

             

            What I think is really strange is that as soon as I create the xpath expression the error occures. The xpath expression isn't modifing the xml at all, so the data shouldn't be changed at all.

             

            Could it be, that the responseWriter isn't getting any content at all to render? But I also tried the put a "return;" at the beginning in order to skip all the rest of the code. But that is working fine!

             

            What is creating a CDATA element? It seems that the responseWriter create an CDATA element and inside that I try to put another CDATA element. But why at the xpath? I could understand the problem when I put the xml inside the responseWriter, but not at reading the xml.

             

             

            I put an <a4j:log> - tag at my page and I am getting this message:

             

             

             

            info [10:51:14.541]: Received 'begin' event from <div id=j_idt7:regelWerkGrafik ...>

            info [10:51:14.824]: Received 'beforedomupdate' event from <div id=j_idt7:regelWerkGrafik ...>

            info [10:51:14.826]: Server returned responseText: <html><head><title>JBoss Web/7.0.1.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.IllegalStateException: CDATA tags may not nest com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:630)  javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:172)  javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:342)  com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)  com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:123) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) org.richfaces.webapp.PushFilter.doFilter(PushFilter.java:144) </pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.1.Final logs.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.1.Final</h3></body></html>

            error[10:51:14.828]: Received 'error@httpError' event from <div id=j_idt7:regelWerkGrafik ...>

            error[10:51:14.829]: [500] undefined: undefined


             

             

             

             

            when I create the xpath expression. When I remove the xpath expression, I get this message (and it is working)

             


             

            info [10:54:56.034]: Received 'begin' event from <div id=j_idt7:regelWerkGrafik ...>

            info [10:54:56.257]: Received 'beforedomupdate' event from <div id=j_idt7:regelWerkGrafik ...>

            info [10:54:56.264]: Listing content of response changes element:
            Element update for id=j_idt7:regelWerkGrafik
            <update id="j_idt7:regelWerkGrafik"><![CDATA[<div id="j_idt7:regelWerkGrafik" class="rf-tab"><div class="rf-tab-cnt" id="j_idt7:regelWerkGrafik:content"><?xml version="1.0" encoding="UTF-8"?> <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><span style="display:none;" id="j_idt7:j_idt204"><script type="text/javascript">new RichFaces.ui.Poll("j_idt7:j_idt204",{"enabled":true,"interval":5000,"ontimer":function(event){RichFaces.ajax("j_idt7:j_idt204",event,{"incId":"1"} )}} )</script></span></div><script type="text/javascript">new RichFaces.ui.Tab("j_idt7:regelWerkGrafik",{"index":3,"leave":null,"togglePanelId":"j_idt7:j_idt34","switchMode":"ajax","name":"Regelwerk","enter":null,"disabled":false} )</script></div>]]></update>
            Element update for id=javax.faces.ViewState
            <update id="javax.faces.ViewState"><![CDATA[2328161482662310700:-5043816309040202583]]></update>
            Element extension for id=org.richfaces.extension
            <extension  id="org.richfaces.extension"><complete>RichFaces.$('j_idt7:j_idt34').onCompleteHandler('Regelwerk');;</complete></extension>

            info [10:54:56.279]: Received 'success' event from <div id=j_idt7:regelWerkGrafik ...>

            info [10:54:56.281]: Received 'complete' event from <div id=j_idt7:regelWerkGrafik ...>

            • 3. Re: Own Component with UIComponentBase and XPath Expression issue
              haukegulich

              I just wanted to create a minimal example and I copied the content to a simple xhtml page

               

               

              {code:xml}

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

              <html xmlns="http://www.w3.org/1999/xhtml"

                  xmlns:f="http://java.sun.com/jsf/core"

                  xmlns:h="http://java.sun.com/jsf/html"

                  xmlns:ui="http://java.sun.com/jsf/facelets"

                  xmlns:a4j="http://richfaces.org/a4j"

                  xmlns:rich="http://richfaces.org/rich"

                  xmlns:cu="http://127.0.0.1:8080/custom-taglib">

               

              <f:view>

               

                  <h:head>

                      <title>Schwimmbad-Steuerung Version 0.1</title>

                   </h:head>

               

                  <h:body>

                      <h:form>

               

               

                          <cu:custom/>

               

                          <a4j:log />

                      </h:form>

                  </h:body>

              </f:view>

              </html>{code}

               

              And after running that example I got this in my browser

               

              java.lang.NoClassDefFoundError: org/jaxen/JaxenException
              at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
              at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
              at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:183)
              at de.hauke.client.playground.MyCustom.encodeEnd(MyCustom.java:34)

               

               

              I noticed this issue earlier as I created a simple standalone application (without web application or jboss) but I thought that I would get this error message also from jboss when Jboss is missing this library.

               

              I will try to add the dependency to my project and hopefully then its working !! :-)

               

               

              Now its working with Jaxen Version 1.1.1 to my pom.xml.

               

              But still a strange behaivor from JBoss. Anyway, thank you!!!