Topic
6 replies Latest Post - ‏2011-06-03T05:44:40Z by pjensen1
kennas
kennas
6 Posts
ACCEPTED ANSWER

Pinned topic Feature Focus Week: JSP 2.2 and EL 2.2

‏2010-05-27T20:51:02Z |
Since JSP 1.2 and its EL 1.0 were released as part of Java EE 5, there have been two additional Maintenance Releases(MR) that contained some minor feature enhancements, clarifications and removal of errors for each specification. Click the following for a quick reference to the change log for those MRs: http://jcp.org/aboutJava/communityprocess/maintenance/jsr245/245ChangeLog.html.

As part of the first MR, the EL specification was no longer a part of the JSP specification and was re-versioned to 1.1. Then as part of Java EE 6, the MRs were folded back into the specifications. Since there were schema changes in the MRs, the JSR 245 expert group warranted a new point version of the specifications. JSP was then re-versioned to 2.2 and the EL was re-versioned to 2.2 also to keep them aligned.

Some of the JSP features include the following:

• Declaring default content Type, default buffer size and forcing an error for undeclared Namespaces in a jsp-property-group.
Here is an example of a jsp-property-group with these new attributes:

<jsp-property-group> <url-pattern>PGContentAndBuffer.jsp</url-pattern> <default-content-type>text/html; charset=Shift_JIS</default-content-type> <buffer>9000</buffer> </jsp-property-group> <jsp-property-group> <url-pattern>Undeclared.jsp</url-pattern> <error-on-undeclared-namespace>true</error-on-undeclared-namespace> </jsp-property-group>


• New attribute to omit a <jsp:attribute> within a <jsp:element>
Here is an example of using omit in a table:

<c:set var=
"trueEL" value=
"true"/> <c:set var=
"falseEL" value=
"false"/> <c:set var=
"blahEL" value=
"blah"/> <%

boolean jspExpressionTrue = 

true; 

boolean jspExpressionFalse = 

false;%>   <jsp:element name=
"table"> <jsp:attribute name=
"border" omit=
"false">1</jsp:attribute> <jsp:body> <jsp:element name=
"tr"> <jsp:element name=
"td">Column1</jsp:element> <jsp:element name=
"td">Column2</jsp:element> <jsp:element name=
"td">Column3</jsp:element> <jsp:element name=
"td">Column4</jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"true">3</jsp:attribute> <jsp:body>First row - omit is 

true on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"false">3</jsp:attribute> <jsp:body>Second row - omit is 

false on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"blah">3</jsp:attribute> <jsp:body>Third row - omit is blah on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan">3</jsp:attribute> <jsp:body>Fourth row - omit is unspecified</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"${trueEL}">3</jsp:attribute> <jsp:body>Fifth row - omit is an EL expression evaluated to 

true on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"${falseEL}">3</jsp:attribute> <jsp:body>Sixth row - omit is an EL expression evaluated to 

false on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"${blahEL}">3</jsp:attribute> <jsp:body>Seventh row - omit is an EL expression evaluated to blah on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"<%=jspExpressionTrue%>">3</jsp:attribute> <jsp:body>Eighth row - omit is a JSP Expression evaluated to 

true on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> <jsp:element name=
"tr"> <jsp:element name=
"td"> <jsp:attribute name=
"colspan" omit=
"<%=jspExpressionFalse%>">3</jsp:attribute> <jsp:body>Ninth row - omit is a JSP Expression evaluated to 

false on colspan</jsp:body> </jsp:element> <jsp:element name=
"td"> Next column </jsp:element> </jsp:element> </jsp:body> </jsp:element>


Some of the EL features include the following:

• Methods javax.el.ExpressionFactory.newInstance() and javax.el.ExpressionFactory.newInstance(Properties) that will create a a new instance of an ExpressionFactory. Adding these factory methods help make the EL standalone from JSP. You are no longer bound to having JSP create the EL ExpressionFactory and this gives you the ability to configure what EL implementation you would like to use - not just the one provided by the JSP container.

• EL Operators ‘[]’ and ‘.’ now accept optional parameters used for method invocations.
Here is an example of using parameters in EL operators:

TestBean foo = 

new TestBean(); ValueExpression fooVE = fact.createValueExpression(foo, TestBean.class); ctxt.getVariableMapper().setVariable(
"foo", fooVE); String myString = 
"writeStuff"; ValueExpression myStringExpression = fact.createValueExpression(myString, String.class); ctxt.getVariableMapper().setVariable(
"myString", myStringExpression); ValueExpression myValueExpression1 = fact.createValueExpression(ctxt,
"#{foo.writeStuff('param1')}",java.lang.String.class); pw.println(
"foo.writeStuff('param1')=" + myValueExpression1.getValue(ctxt));   ValueExpression myValueExpression2 = fact.createValueExpression(ctxt,
"#{foo[myString]('param2')}",java.lang.String.class); pw.println(
"foo[myString]('param2')=" + myValueExpression2.getValue(ctxt));   MethodExpression myMethodExpression = fact.createMethodExpression(ctxt, 
"#{foo.writeStuff}", String.class, 

new Class<?>[] 
{String.class
}); Object myMethodReturn = myMethodExpression.invoke(ctxt, 

new String[] 
{
"dummyParam"
}); pw.println(
"myMethodReturn="+myMethodReturn); 
//this should use the param value in the EL ('using brackets in EL') not the invoke -  MethodExpression myMethodExpression1 = fact.createMethodExpression(ctxt, 
"#{foo[myString]('using brackets in EL')}", String.class, 

new Class<?>[] 
{String.class
}); Object myMethodReturn1 = myMethodExpression1.invoke(ctxt, 

new String[] 
{
"using brackets"
}); pw.println(
"myMethodReturn1="+myMethodReturn1);

• A method javax.el.ELResolver.invoke(eLContext, base, method, paramTypes, params) has been added that will invoke the given method on a given base object.

• A method java.el.BeanELResolver.invoke(eLContext, base, method, paramTypes, params) has been added that will try to resolve method invocations in a bean.

• A new class javax.el.ValueReference and a corresponding method javax.el.ValueExpression.getValueReference(eLContext) for resolving a base/property pair for a ValueExpression.

-Stephen Kenna – Web Tier Lead Architect
-Robert Goff – JSP and Session Architect.
Updated on 2011-06-03T05:44:40Z at 2011-06-03T05:44:40Z by pjensen1
  • PetrH
    PetrH
    26 Posts
    ACCEPTED ANSWER

    Re: Feature Focus Week: JSP 2.2 and EL 2.2

    ‏2010-09-17T10:54:59Z  in response to kennas
    Hello, I was just looking for the JSP & EL spec support in WAS 8.0 beta (cause we were facing some strange issue with EL in particular) and found out the available information quite confusing:

    1. https://www14.software.ibm.com/iwm/web/cc/earlyprograms/websphere/wsasoa/index.shtml
    notes JSP 2.2 which seems to be correct

    2. http://publib.boulder.ibm.com/infocenter/wasinfo/beta/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rovr_specs.html
    notes JSP 2.1 only which doesn't seem to be correct

    3. I tried to briefly look at the libs right in WAS, but there are many of these classes at many places. I guess the EL/JSP API classes could be found in plugins/javax.j2ee.el.jar and plugins/javax.j2ee.jsp.jar whilie spec is in plugins/com.ibm.ws.webcontainer.jar
    - plugins/javax.j2ee.el.jar META-INF/MANIFEST.MF states version to be likely 2.1 (Bundle-Version: 2.1) while the included classes really appear to be of 2.2
    - plugins/javax.j2ee.jsp.jar META-INF/MANIFEST.MF states version 2.2 (Bundle-Version: 2.2) and it seems like the included classes might be of 2.1 (which is probably not an issue)
    - plugins/com.ibm.ws.webcontainer.jar META-INF/MANIFEST.MF can't be used to determine much, and there's a mix of classes from Apache Jasper and Your own impl, I guess here it's fine.

    Could you please clarify that in the docs? And EL is at 2.2 or 2.2.1?
    • R.Goff
      R.Goff
      4 Posts
      ACCEPTED ANSWER

      Re: Feature Focus Week: JSP 2.2 and EL 2.2

      ‏2010-09-17T13:40:46Z  in response to PetrH
      Sorry for the version confusion. We will be correcting the documentation to say that we support JSP 2.2. The EL version is also at 2.2. Can you elaborate on the strange issue that you are seeing with the EL? Thanks.

      Robert Goff
      WAS JSP/Session Architect
      • PetrH
        PetrH
        26 Posts
        ACCEPTED ANSWER

        Re: Feature Focus Week: JSP 2.2 and EL 2.2

        ‏2010-09-17T14:27:16Z  in response to R.Goff
        Basically we were getting an exception like the following:
        javax.el.ELException: /test/MainContextForm.xhtml at line 6 and column 44 model="#{this.menuModel.menu}": Cannot convert org.primefaces.model.DefaultMenuModel@24912491 of type class org.primefaces.model.DefaultMenuModel to interface org.primefaces.model.MenuModel
        at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:92)
        at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:260)
        at org.primefaces.component.menu.Menu.getModel(Menu.java:97)
        at org.primefaces.component.menu.AbstractMenu.buildMenuFromModel(AbstractMenu.java:28)
        at org.primefaces.component.menu.MenuRenderer.encodeEnd(MenuRenderer.java:37)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:490)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:618)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
        at org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer.encodeEnd(HtmlCompositeComponentRenderer.java:71)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:490)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:618)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
        at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1117)
        at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:231)
        at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:86)
        at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:218)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1136)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:706)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:433)
        at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1009)
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3527)
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:303)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:970)
        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1593)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:192)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
        at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
        at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
        at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
        at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1574)

        (with Primefaces 2.1 in our war/WEB-INF/classes/ and MyFaces/EL from WAS) and as we've never encountered it at other development environments (mainly Tomcat) we were looking for any possible differences including EL.

        Note that org.primefaces.model.MenuModel is an interface and org.primefaces.model.DefaultMenuModel implements it.

        However after server restart the exception disappeared and didn't reappear so far. We think it might be a classloading related issue.

        We've also recently switched from MyFaces 2.0 to Sun JSF 2.0 RI (http://www.ibm.com/developerworks/forums/thread.jspa?threadID=346760) which means few more changes in the environment and it will be interesting to see if that issue will evetually reappear.
        • kennas
          kennas
          6 Posts
          ACCEPTED ANSWER

          Re: Feature Focus Week: JSP 2.2 and EL 2.2

          ‏2010-09-17T14:49:05Z  in response to PetrH
          Just wondering if you were packaging Myfaces 2.0 in your application, or using the supported one that comes with WebSphere v8? We have optimizations built in to our common annotation scanning and also have CDI support when using the one in the runtime.
          • PetrH
            PetrH
            26 Posts
            ACCEPTED ANSWER

            Re: Feature Focus Week: JSP 2.2 and EL 2.2

            ‏2010-09-17T15:33:42Z  in response to kennas
            Yes, before switching to JSF 2.0 RI we were using MyFaces 2.0 bundled into WAS.
        • pjensen1
          pjensen1
          1 Post
          ACCEPTED ANSWER

          Re: Feature Focus Week: JSP 2.2 and EL 2.2

          ‏2011-06-03T05:44:40Z  in response to PetrH
          Interesting PetrH, just ran into similar exceptions as well, server running centos/apache, a restart and everything was back to normal. Might need to investigate further if the issue re-emerges.

          Peter Jensen
          Social Media