javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-2689

Composite Component Default attr values not available programmatically when default value is a El

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.18
    • Component/s: None
    • Labels:
      None

      Description

      When default attribute value in a composite component is an El, calling getAttributes().get("myattribute") returns null.

      For now, I must evaluate programmatically #

      {cc.attrs.myattribute}

      to retrieve the attribute value.

      Sample composite :

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      	xmlns:ui="http://java.sun.com/jsf/facelets"
      	xmlns:f="http://java.sun.com/jsf/core"
      	xmlns:h="http://java.sun.com/jsf/html"
      	xmlns:c="http://java.sun.com/jsp/jstl/core"
      	xmlns:cc="http://java.sun.com/jsf/composite">
      
      	<cc:interface componentType="org.jboss.seam.faces.InputContainer">
      		<cc:attribute name="styleClass" default="control-group #{cc.attrs.invalid ? 'error' : ''}"/>
      	</cc:interface>
      	<cc:implementation>
              blabla
      	</cc:implementation>
      </ui:composition>
      
      @FacesComponent(UIInputContainer.COMPONENT_TYPE)
      public class UIInputContainer extends UIComponentBase implements
      		NamingContainer {
      
      	@Override
      	public void encodeBegin(final FacesContext context) throws IOException {
      		if (!isRendered()) {
      			return;
      		}
      		//this one returns null
      		Object attribute1 = getAttributes().get("styleClass");
      		//this one returns the real value
      		FacesContext facesContext = FacesContext.getCurrentInstance();
      		ELContext elContext = facesContext.getELContext();
      		ValueExpression targetExpression = facesContext
      				.getApplication()
      				.getExpressionFactory()
      				.createValueExpression(elContext, "#{cc.attrs.styleClass}",
      						Object.class);
      		Object attribute2 = targetExpression.getValue(elContext);
      		...
      	}
      }
      

        Issue Links

          Activity

          Hide
          Ed Burns added a comment -

          The implementation of the cc:interface handler builds up a composite component metadata data structure that stores the default value. The implementation of that data structure either evaluates the EL expression for the default or saves it as a ValueExpression. I'm not sure which at this point. Need more investigation.

          Show
          Ed Burns added a comment - The implementation of the cc:interface handler builds up a composite component metadata data structure that stores the default value. The implementation of that data structure either evaluates the EL expression for the default or saves it as a ValueExpression. I'm not sure which at this point. Need more investigation.
          Hide
          Manfred Riem added a comment -

          Can you please let us know which version is affected?

          Show
          Manfred Riem added a comment - Can you please let us know which version is affected?
          Hide
          gonzalad added a comment -

          Thanks for taking this issue.
          Affected version is 2.1.5.
          Do you need a testcase ?

          Show
          gonzalad added a comment - Thanks for taking this issue. Affected version is 2.1.5. Do you need a testcase ?
          Hide
          Manfred Riem added a comment -

          A testcase is always welcome. Have you tried it on the latest 2.1 release?

          Show
          Manfred Riem added a comment - A testcase is always welcome. Have you tried it on the latest 2.1 release?
          Hide
          Ed Burns added a comment -

          Manfred asserted that code from PropertyHandlerManager.java could be backported from JSF 2.2 to 2.1 to handle this. Specifically lines 83 and 253 - 286.

          I noticed that Imre had committed these lines as part of the fix for JAVASERVERFACES-1966.

          That makes sense to me, but I'd like to get Imre's input.

          Show
          Ed Burns added a comment - Manfred asserted that code from PropertyHandlerManager.java could be backported from JSF 2.2 to 2.1 to handle this. Specifically lines 83 and 253 - 286. I noticed that Imre had committed these lines as part of the fix for JAVASERVERFACES-1966 . That makes sense to me, but I'd like to get Imre's input.
          Hide
          gonzalad added a comment -

          Sorry for being late, I've uploaded a little testcase on my github repo https://github.com/gonzalad/mojarra2869.

          I didn't see the button to add a file in this JIRA (missed my googles ?).

          Testcase shows the issue on mojarra 2.1.17.

          To use it :

          • mvn package
          • install resulting war on Tomcat (tested it on 7.0.29).
          • browse http://localhost:8080/mojarra2869/index.jsf
          • this should show that getAttributes().get("value") returns null instead of 'control-group true'.
          Show
          gonzalad added a comment - Sorry for being late, I've uploaded a little testcase on my github repo https://github.com/gonzalad/mojarra2869 . I didn't see the button to add a file in this JIRA (missed my googles ?). Testcase shows the issue on mojarra 2.1.17. To use it : mvn package install resulting war on Tomcat (tested it on 7.0.29). browse http://localhost:8080/mojarra2869/index.jsf this should show that getAttributes().get("value") returns null instead of 'control-group true'.
          Hide
          Manfred Riem added a comment -

          Applied to 2.1 branch,

          svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2689, r=rogerk, allow for evaluation of EL expressions in cc:attribute default values."
          Sending jsf-ri\src\main\java\com\sun\faces\facelets\tag\composite\PropertyHandlerManager.java
          Adding test\agnostic\facelets\cc\nb-configuration.xml
          Adding test\agnostic\facelets\cc\src\main\webapp\defaultEl.xhtml
          Adding test\agnostic\facelets\cc\src\main\webapp\defaultEl2.xhtml
          Adding test\agnostic\facelets\cc\src\main\webapp\resources\defaultEl
          Adding test\agnostic\facelets\cc\src\main\webapp\resources\defaultEl\component.xhtml
          Adding test\agnostic\facelets\cc\src\test\java\com\sun\faces\test\agnostic\facelets\composite\Issue2689IT.java
          Transmitting file data ......
          Committed revision 11482.

          Show
          Manfred Riem added a comment - Applied to 2.1 branch, svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2689 , r=rogerk, allow for evaluation of EL expressions in cc:attribute default values." Sending jsf-ri\src\main\java\com\sun\faces\facelets\tag\composite\PropertyHandlerManager.java Adding test\agnostic\facelets\cc\nb-configuration.xml Adding test\agnostic\facelets\cc\src\main\webapp\defaultEl.xhtml Adding test\agnostic\facelets\cc\src\main\webapp\defaultEl2.xhtml Adding test\agnostic\facelets\cc\src\main\webapp\resources\defaultEl Adding test\agnostic\facelets\cc\src\main\webapp\resources\defaultEl\component.xhtml Adding test\agnostic\facelets\cc\src\test\java\com\sun\faces\test\agnostic\facelets\composite\Issue2689IT.java Transmitting file data ...... Committed revision 11482.

            People

            • Assignee:
              Manfred Riem
              Reporter:
              gonzalad
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: