Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3283

#{cc.attr} attributes fail when a child component is accessed outside of the composite component (i.e. in action listeners or other events)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.0.7
    • None
    • General
    • None
    • Mac OS 10.6, Tomcat 7

    Description

      If you reference a property of child component anywhere outside of the composite's context (i.e. in an action method, a component system event listener, etc.), the property will not be evaluated properly if the expression is a composite component attribute (i.e. "#

      {cc.attrs.property}

      "). This is because the EL evaluation code can't find the parent composite component.

      For example, consider the composite component:

      <?xml version="1.0"?>
      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:composite="http://java.sun.com/jsf/composite">

      <composite:interface>
      <composite:attribute name="label" />
      <composite:attribute name="value" required="true" />
      </composite:interface>

      <composite:implementation>
      <h:outputLabel for="input" value="#

      {cc.attrs.label}

      " />
      <h:inputText id="input" value="#

      {cc.attrs.value}

      " />
      </composite:implementation>
      </html>

      The calling page:

      <!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ez="http://java.sun.com/jsf/composite/demo">

      <h:head></h:head>
      <h:body>
      <h:form id="form">
      <h:messages />
      <ez:input id="composite" label="Enter something:"
      value="#

      {testBean.value}

      " />
      <h:commandButton value="Submit" action="#

      {testBean.testCcAttribute}

      " />
      </h:form>
      </h:body>
      </html>

      Here's testBean.testCcAttribute():

      public String testCcAttribute()

      { HtmlInputText input = (HtmlInputText)FacesContext.getCurrentInstance().getViewRoot().findComponent("form:composite:input"); UIComponent composite = FacesContext.getCurrentInstance().getViewRoot().findComponent("form:composite"); String message = "Input control label attribute is: " + input.getLabel() + "; Composite label attribute is: " + composite.getAttributes().get("label"); display(message); return null; }

      This action method generates the following message:

      Input control label attribute is: null; Composite label attribute is: Enter something:

      Full example WAR attached.

      Note this is the same as the following issue with Mojarra: http://java.net/jira/browse/JAVASERVERFACES-2009.

      Attachments

        1. myfaces_cc_issue.war
          3.72 MB
          Kito D. Mann

        Activity

          People

            Unassigned Unassigned
            kito99 Kito D. Mann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: