1 Reply Latest reply on May 4, 2009 1:25 PM by juanignaciosl

    Null Session Action and Outjected variables

    earnest.dyke

      Ok, I have been trying to find out why the tsYear property and the outjected value are both null when the page is rendered.


      Here is the xhtml:



      <!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:s="http://jboss.com/products/seam/taglib"
           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:a4j="http://richfaces.org/a4j"
           xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml">
      
           <ui:define name="body">
              <h:form>
                <table>
                <tr>
                  <td class="detailLabel"><h:outputText value="Select year" /></td>
                  <td class="detailData"><h:selectOneListbox id="tsYears"
                     value="#{TimesheetAction.tsYear}" size="1">
                     <a4j:support event="onchange"
                     action="#{TimesheetAction.loadTimesheetsForYear()}" />
                     <f:selectItem itemValue="" itemLabel="-- Select Year" />
                     <f:selectItems value="#{timesheetYears}" />
                    </h:selectOneListbox></td>
                 </tr>
                <s:fragment rendered="#{tsYear!= null}">
                 <tr>
                  <td class="detailLabel"><h:outputText
                       value="Select timesheet" /></td>
                  <td class="detailData"><h:selectOneListbox id="tsList"
                       value="#{TimesheetAction.ts}" size="3"
                       converter="#{TimesheetConverter}">
                       <a4j:support event="onchange"
                             action="#{TimesheetAction.loadEmployeeTimesheetView()}" />
                        <f:selectItem itemValue="" itemLabel="-- Select Timesheet" />
                     <f:selectItems value="#{timesheets}" />
                       </h:selectOneListbox></td>
                  </tr>
                </s:fragment>
                  </table>
                       <s:fragment rendered="#{TimesheetAction.viewable}" id="ts">
                  <table border="1" class="dr-table rich-table">
                    <thead class="dr-table-thead">
                      <tr>
                       <th colspan="#{timesheetView.days}">Hello</th>
                      </tr>
                      <tr class="dr-table-header rich-table-header">
                     <ui:repeat value="#{timesheetView.dates}" var="d">
                       <th class="dr-table-headercell rich-table-headercell"><h:outputText
                         value="#{d}" /></th>
                      </ui:repeat>
                      </tr>
                     </thead>
                    </table>
                  </s:fragment>
                </h:form>
                <h:outputText value="#{TimesheetAction.viewable}" />
                <rich:spacer width="50" />
                <h:outputText value="Year? #{tsYear}" />
           </ui:define>
      
      </ui:composition>



      And the action:



      package org.ebsinc.admin.action;
      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.io.Serializable;
      import java.text.SimpleDateFormat;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.faces.context.FacesContext;
      import javax.faces.model.SelectItem;
      
      import org.ebsinc.admin.entity.Employee;
      import org.ebsinc.admin.entity.EmployeeTimesheet;
      import org.ebsinc.admin.entity.Timesheet;
      import org.ebsinc.admin.entity.TimesheetView;
      import org.ebsinc.admin.session.TimesheetManager;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      
      @Name("TimesheetAction")
      @Scope(SESSION)
      public class TimesheetAction implements Serializable{
           private static final long serialVersionUID = 1l;
      
           @In(value = "TimesheetManager", create = true)
           TimesheetManager tsMgr;
           
           @In
           FacesContext facesContext;
           
           @Out(required=false,scope=SESSION)
           private Integer tsYear;
      
           @Out(required=false)
           private Timesheet ts;
      
           private TimesheetView timesheetView;
      
           private EmployeeTimesheet employeeTimesheet;
           
           @In
           Employee currentEmployee;
      
           private Boolean viewable;
      
           public TimesheetAction() {
                if (1==1) { }
           }
           public void loadTimesheetView() {
                if (employeeTimesheet == null) {
                     employeeTimesheet = tsMgr.getTimesheet(currentEmployee, ts);
                }
                timesheetView = tsMgr.getTimesheetView(employeeTimesheet);
           }
      
           public String loadEmployeeTimesheetView() {
                loadTimesheetView();
                return null;
           }
      
           public EmployeeTimesheet getEmployeeTimesheet() {
                return employeeTimesheet;
           }
      
           public void setEmployeeTimesheet(EmployeeTimesheet employeeTimesheet) {
                this.employeeTimesheet = employeeTimesheet;
                loadTimesheetView();
           }
      
           @In(required = false, scope = SESSION)
           @Out(scope = SESSION)
           private List<SelectItem> timesheetYears;
      
           @Factory("timesheetYears")
           public void getTimesheetYears() {
                List<SelectItem> l = new ArrayList<SelectItem>(10);
                List<Integer> yrs = tsMgr.getTimeSheetYears();
                for (Integer y : yrs) {
                     SelectItem si = new SelectItem(y.intValue(), y.toString());
                     l.add(si);
                }
                timesheetYears = l;
           }
      
           @In(required = false, scope = SESSION)
           @Out(required = false, scope = SESSION)
           private List<SelectItem> timesheets;
      
           public String loadTimesheetsForYear() {
                List<SelectItem> l = new ArrayList<SelectItem>(26);
                if (tsYear == null) {
                     timesheets = l;
                     return null;
                }
                List<Timesheet> timesheetsList = tsMgr.getTimesheets(tsYear);
                for (Timesheet ts : timesheetsList) {
                     SelectItem si = new SelectItem(ts, getTimesheetDateRange(ts));
                     l.add(si);
                }
                timesheets = l;
                return null;
           }
      
           private String getTimesheetDateRange(Timesheet ts) {
                StringBuffer sb = new StringBuffer();
                SimpleDateFormat sdf = new SimpleDateFormat("d MMM");
                sb.append(sdf.format(ts.getStartDate()));
                sb.append(" - ");
                sdf = new SimpleDateFormat("d MMM yyyy");
                sb.append(sdf.format(ts.getEndDate()));
                return sb.toString();
           }
      
           public Integer getTsYear() {
                return tsYear;
           }
      
           public void setTsYear(Integer tsYear) {
                this.tsYear = tsYear;
           }
      
           public Timesheet getTs() {
                return ts;
           }
      
           public void setTs(Timesheet ts) {
                this.ts = ts;
                if (ts != null) {
                     viewable = true;
                }
           }
      
           public Boolean getViewable() {
                return viewable;
           }
      
           public void setViewable(Boolean viewable) {
                this.viewable = viewable;
           }
      
      }
      



      I have stepped through the code and tsYear has a value in the action and seam.debug shows a value for tsYear in the session scope but it does not display on the page and the areas that are conditionally rendered based on it are not displayed.


      I have spent a day trying to figure this out and I am hoping another set of eyes will quickly see what I have overlooked.


      Thanks in advance for any and all help!


      Earnie!