1 Reply Latest reply on Aug 31, 2009 5:26 AM by nbelaevski

    Access Properties with custom Component in a4j:repeat

    rob.gebhardt

      Hi,

      following Code-Fragment in a JSP let me despair.

      <a4j:repeat value="#{workspace.data.selectedMiddleLevelPanel.actions}" var="action" rowKeyVar="index">
       <me:checkPermission permission="#{action.permission}" toolTip="#{system.completeCmsUrl}">
       <h:panelGroup>
       ...
       </h:panelGroup>
       </me:checkPermission>
      </a4j:repeat>


      The UIComponentELTag for me:checkPermission tries to resolve the ValueExpression permission and toolTip.
      The Property toolTip is for debugging and the Taghandler resolves the ValueExpression for toolTip correctly. But the TagHandler can't resolve the Expression in the Property permission.
      Here the Code for the TagHandler:
      package de.meine_energie.web.taglib.permission;
      
      import javax.el.ValueExpression;
      import javax.faces.component.UIComponent;
      import javax.faces.webapp.UIComponentELTag;
      import javax.servlet.jsp.JspException;
      
      import de.meine_energie.permission.Permission;
      
      
      
      public class CheckPermissionTag extends UIComponentELTag {
      
       private ValueExpression permission = null;
      
       private ValueExpression toolTip = null;
      
       @Override
       public String getComponentType() {
       return "de.meine_energie.web.taglib.permission.CheckPermissionComponent";
       }
      
       @Override
       public String getRendererType() {
       return null;
       }
      
       @Override
       protected void setProperties(UIComponent component) {
       super.setProperties(component);
      
       CheckPermissionComponent permComp = (CheckPermissionComponent)component;
      
       Permission p = (Permission)permission.getValue(getELContext());
       permComp.setPermission(p);
      
      
       if(p != null){
       System.out.println("permission is not null"+p.getAction());
       } else {
       System.out.println("permission is null");
       }
      
       if(toolTip != null){
       String tool = (String)toolTip.getValue(getELContext());
       System.out.println("Tooltip: "+tool);
       System.out.println("valueExpression: "+toolTip.getExpressionString());
      
       } else {
       System.out.println("Tooltip is nulL!!");
       }
       }
      
       @Override
       public int doStartTag() throws JspException {
       System.out.println("doStartTag");
       return super.doStartTag();
       }
      
       public void setPermission(ValueExpression permission) {
       this.permission = permission;
       }
      
       public ValueExpression getPermission() {
       return permission;
       }
      
       @Override
       public int doEndTag() throws JspException {
       release();
       return super.doEndTag();
       }
      
       @Override
       public void release() {
       permission = null;
       toolTip = null;
       super.release();
       }
      
       public void setToolTip(ValueExpression toolTip) {
       this.toolTip = toolTip;
       }
      
       public ValueExpression getToolTip() {
       return toolTip;
       }
      
      
      }
      


      Why can't i access the Property in the loop? Is there another way to resolve ValueExpressions?
      Can anybody help me please?

      ... thanks!

        • 1. Re: Access Properties with custom Component in a4j:repeat
          nbelaevski

          Hi,

          That't because you're trying to evaluate this property in component tree build time, however a4j:repeat as another JSF iteration component makes it available on render-time. The right solution is not to evaluate these properties, but add them to VariableMapper - see Facelets source codes - all templating features are built around that.