title: JSF 2.X UI Component use of ValueExpression
body: <p>I am trying to build a simple component to understand how and why JSF 2.X works the way it does. I have been using the newer annotations and have been trying to piece together a clear example.</p>
  
  <p>So I have built my component and deployed it in a xhtml file as follows:</p>
  
  <pre><code>&lt;kal:day value="K.Day" title="Kalendar" model="#{kalendarDay}"/&gt;
  </code></pre>
  
  <p>The within the UIComponent I do the following:</p>
  
  <pre><code>ValueExpression ve      = getValueExpression("model");
  if (ve != null) 
  {
      System.out.println("model expression "+ve.getExpressionString());
      model = (KalendarDay) ve.getValue(getFacesContext().getELContext());
      System.out.println("model "+model);
  }
  </code></pre>
  
  <p>The expression "#{kalendarDay}" is correctly displayed indicating that the value has been successfully transmitted between the page and the component.  However the evaluation of the expression results in "null".</p>
  
  <p>This seems to indicate that the backing bean is unavailable at this point, although the page correctly validates and deploys.  So I am 95% certain that the bean is there at run time.</p>
  
  <p>So perhaps this is a phase thing?  Should I be evaluating this in the decode of the renderer and setting the value in the attributes map?  I am still a little confused about the combination of actual values and value expressions.</p>
  
  <p>So my question is where should I fetch and evaluate the valueExpression for model and should I store the result of the evaluation in the UIComponent or should I simply evaluate it every time?</p>
  
  <p>SSCCE files below I think these are the only required files to demonstrate the problem</p>
  
  <p>Bean Interface -----</p>
  
  <pre><code>/**
   * 
   */
  package com.istana.kalendar.fixture;
  
  import java.util.Date;
  
  /**
   * @author User
   *
   */
  public interface KalendarDay
  {
      public      Date        getDate();
  }
  </code></pre>
  
  <p>Bean Implementation ---</p>
  
  <pre><code>/**
   * 
   */
  package com.istana.kalendar.session.wui;
  
  import java.util.Calendar;
  import java.util.Date;
  
  import javax.ejb.Stateful;
  import javax.inject.Named;
  
  import com.istana.kalendar.fixture.KalendarDay;
  
  /**
   * @author User
   *
   */
  @Named      ("kalendarDay")
  @Stateful
  public class KalKalendarDay
      implements KalendarDay
  {
  
      private     Calendar        m_date  =   Calendar.getInstance();
  
      /* (non-Javadoc)
       * @see com.istana.kalendar.fixture.KalendarDay#getDate()
       */
      @Override
      public      Date            getDate()
      {
          return m_date.getTime();
      }
  
  }
  </code></pre>
  
  <p>UIComponent ---</p>
  
  <pre><code>/**
   * 
   */
  package com.istana.kalendar.fixture.jsf;
  
  import javax.el.ValueExpression;
  import javax.faces.component.FacesComponent;
  import javax.faces.component.UIOutput;
  
  import com.istana.kalendar.fixture.KalendarDay;
  
  /**
   * @author User
   *
   */
  @FacesComponent     (value=UIDay.COMPONENT_TYPE)
  public class UIDay  extends UIOutput
  {
      static      final
      public      String          COMPONENT_TYPE      =   "com.istana.kalendar.fixture.jsf.Day";
  
      static      final
      public      String          COMPONENT_FAMILY    =   "com.istana.kalendar.fixture.jsf.Day";
  
      private     KalendarDay     m_model;
  
      private     String          m_title;
  
      @Override
      public      String          getRendererType() 
      {
          return UIDayRenderer.RENDERER_TYPE;
      }
  
      @Override
      public      String          getFamily() 
      {
          return COMPONENT_FAMILY;
      }
  
      public      KalendarDay     getModel()
      {
          KalendarDay     model = (KalendarDay) getStateHelper().eval("model");
  
          System.out.println("model "+model);
  
          return model;
      }
  
      public      void            setModel(KalendarDay model)
      {
          getStateHelper().put("model",model);
      }
  
      public      String          getTitle()
      {
          return (String) getStateHelper().eval("title");
      }
  
      public      void            setTitle(String title)
      {
          getStateHelper().put("title",title);
      }
  }
  </code></pre>
  
  <p>UIComponentRenderer ---</p>
  
  <pre><code>/**
   * 
   */
  package com.istana.kalendar.fixture.jsf;
  
  import java.io.IOException;
  
  import javax.el.ValueExpression;
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseWriter;
  import javax.faces.render.FacesRenderer;
  import javax.faces.render.Renderer;
  
  import com.istana.kalendar.fixture.KalendarDay;
  
  /**
   * @author User
   *
   */
  @FacesRenderer  (componentFamily    = UIDay.COMPONENT_FAMILY
                  ,rendererType       = UIDayRenderer.RENDERER_TYPE
                  )
  public class UIDayRenderer extends Renderer
  {
      static      final
      public      String      RENDERER_TYPE   =   "com.istana.kalendar.fixture.jsf.DayRenderer";
  
      @Override
      public      void        encodeBegin (FacesContext context,UIComponent component) 
          throws IOException 
      {
          UIDay uic = (UIDay) component;
  
          ResponseWriter writer = context.getResponseWriter();
          writer.startElement("p", uic);
          /*
           * This is the call that triggers the println
           */
          writer.write("Day - "+uic.getModel().getDate());
      }
  
      @Override
      public      void        encodeEnd   (FacesContext context,UIComponent component) 
              throws IOException 
      {
          ResponseWriter writer = context.getResponseWriter();
          writer.endElement("p");
          writer.flush();
      }
  }
  </code></pre>
  
  <p>kalendar.taglib.xml ---</p>
  
  <pre><code>&lt;facelet-taglib 
      id="kalendar"
      xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
      version="2.0"
  &gt;
  
      &lt;namespace&gt;http://istana.com/kalendar&lt;/namespace&gt;
      &lt;tag&gt;
          &lt;tag-name&gt;day&lt;/tag-name&gt;
          &lt;component&gt;
              &lt;component-type&gt;com.istana.kalendar.fixture.jsf.Day&lt;/component-type&gt;
          &lt;/component&gt;
      &lt;/tag&gt;
  
  &lt;/facelet-taglib&gt;
  </code></pre>