5 Replies Latest reply on Aug 27, 2012 1:44 AM by mcmurdosound

    JSF 2.2 and java.util.Sets

    fastroller

      Is there any planning around readying RichFaces for JSF 2.2? I took a milestone release for Mojarra and upgraded the JSF libs on JBoss 7.1. Sadly Richfaces causes my application to fail. It appears there are some improvements around UIComponent that are not backwards compatible. JSF components now implement pass through attributes which is not handled by Richfaces.

       

      If you're wondering why I want to move to JSF2.2 it is because it now handles Set data models. In the mean time I will use an earlier snapshot of JSF2.2 that doesn't have this backwards compatibility break and continue to use Sets!

       

      If anyone is interested here is my sleuthing:

       

      Exception thrown

      Caused by: java.lang.AbstractMethodError

          at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startElement(HtmlResponseWriter.java:635) [jsf-impl-2.2.0-m05.jar:2.2.0-m05-SNAPSHOT]

          at com.sun.faces.renderkit.html_basic.ScriptRenderer.startElement(ScriptRenderer.java:60) [jsf-impl-2.2.0-m05.jar:2.2.0-m05-SNAPSHOT]

          at com.sun.faces.renderkit.html_basic.ScriptRenderer.encodeEnd(ScriptRenderer.java:106) [jsf-impl-2.2.0-m05.jar:2.2.0-m05-SNAPSHOT]

          at org.richfaces.component.UITransient.encodeEnd(UITransient.java:236) [richfaces-core-impl-4.2.2.Final.jar:4.2.2.Final]

      Mojarra implementation

          public void startElement(String name, UIComponent componentForElement)
                throws IOException {
      
              if (name == null) {
                  throw new NullPointerException(MessageUtils.getExceptionMessageString(
                        MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "name"));
              }
              closeStartIfNecessary();
              isScriptOrStyle(name);
              scriptOrStyleSrc = false;
              if ("cdata".equalsIgnoreCase(name)) {
                  isCdata = true;
                  startCDATA();
                  return;
              } else if (writingCdata) {
                  // starting an element within a cdata section,
                  // keep escaping disabled
                  isCdata = false;
                  writingCdata = true;
              }
      
              writer.write('<');
              writer.write(name);
              
              if (null != componentForElement) {
                  Map passThroughAttrs = componentForElement.getPassThroughAttributes(false);
                  if (null != passThroughAttrs && !passThroughAttrs.isEmpty()) {
                      considerPassThroughAttributes(passThroughAttrs);
                  }
              }
              
              closeStart = true;
      
          }
       
      
        • 1. Re: JSF 2.2
          healeyb

          Andrew, BalusC has written a render kit which allows attributes not supported by the JSF component to get passed on

          to the generated HTML tag, this having been done to allow support for HTML 5 attributes (which would otherwise be

          ignored).

           

          I just vaguely wondered if this could have any application in your situation:

           

          http://balusc.blogspot.co.uk/2012/06/adding-html5-attributes-to-standard-jsf.html

          http://showcase-omnifaces.rhcloud.com/showcase/renderkits/Html5RenderKit.xhtml

           

          Regards,

          Brendan.

          • 2. Re: JSF 2.2
            fastroller

            Thanks, I've heard about this render kit. However, its not the feature I'm after - I just want to use java Sets on repeat components. Early snapshot versions of 2.2 incorporated this feature, but newer milestone releases break compatibility with Richfaces. I might just patch Mojarra 2.1.X series to use sets and wait for JavaEE7 which will probably incorportate JSF 2.2.

             

            Cheers

            • 3. Re: JSF 2.2
              mcmurdosound

              You could convert your sets to lists or arrays. But this would change the collection. Or do some transient stuff where you handle converting from set to list and the other way around in a managed bean. This depends on your needs. (just for output or do you want to modify set from the frontend?)

              • 4. Re: JSF 2.2
                fastroller

                Thanks Christian,

                 

                I initially created my own CollectionDataModel that would handle Sets, but this required me to explicitly convert my domain model sets to a DataModel in a managed bean. That was too much work so I created an EL function to do it for me. Once again, that was just far too much work when it should be done by the framework. After all, that is the point of a framework : to make the mundane tasks easy. So I just compiled my own version of JSF 2.1 that works with sets and works on JBoss7.1. That is the joy of open source.

                • 5. Re: JSF 2.2
                  mcmurdosound

                  Over the years we've created many helper functions usable from EL. Like concat, substring, listToSet, contains or to get the clientId relative to a root element (if someone uses duplicate IDs which still produce different clientIds)