2 Replies Latest reply on Jun 24, 2007 11:01 AM by amitdk

    Problem with entity in session scope and JSF inputText

    amitdk

      I've spent too much time on this so far and am wondering if conceptually I am doing something wrong. I would imagine this to be a fairly common use case for folks, so here's the issue:
      Here's a snippet of my xhtml page -

       <s:decorate template="layout/edit.xhtml">
       <ui:define name="label">Timeline</ui:define>
       <h:selectOneMenu id="timeline" value="#{task.selectedTimeline}" required="false"
       immediate="true">
       <f:valueChangeListener type="com.edwardjones.statusreporting.view.TimelineChangeListener" />
       <s:selectItems id="timelinelst" value="#{timelineList}"
       var="timeline" label="#{timeline.description}" />
       <s:convertEntity />
       <a:support event="onchange" reRender="dt"/>
       </h:selectOneMenu>
       </s:decorate>
      
       <h:inputText id="dt"
       value="#{selectedTimeline.startDate}">
       <f:convertDateTime pattern="MM/dd/yyyy"/>
       </h:inputText>
      
       <jp:popupCalendar id="date_popup"
       for="date"
       format="MM/dd/yyyy"
       rendered="#{!disabled and rendered != false}">
       <h:graphicImage url="img/calendar.gif"
       title="Click here to select date"/>
       </jp:popupCalendar>
      


      The TimelineChangeListener is as follows:
      @Name("timelinechange")
      public class TimelineChangeListener implements ValueChangeListener
      {
       @Out(value="selectedTimeline", required = false, scope = SESSION)
       Timeline timeline;
      
       public void processValueChange(ValueChangeEvent arg0)
       throws AbortProcessingException {
       timeline = (Timeline) arg0.getNewValue();
      
       // TODO Auto-generated method stub
       System.out.println("timeline selection");
       }
      }
      


      The Timeline entity looks as follows:
      /**
       * Timeline generated by hbm2java
       */
      @Entity
      @Name("timeline")
      @Role(name="selectedTimeline", scope=SESSION)
      @Table(name = "timeline", catalog = "statreport", uniqueConstraints = @UniqueConstraint(columnNames = "description"))
      public class Timeline implements java.io.Serializable
      {
       private int id;
      
       private String description;
      
       public Timeline()
       {
       }
      
       public Timeline(int id, String description)
       {
       this.id = id;
       this.description = description;
       }
      
       @Id
       @Column(name = "id", unique = true, nullable = false)
       @NotNull
       public int getId()
       {
       return this.id;
       }
      
       public void setId(int id)
       {
       this.id = id;
       }
      
       @Column(name = "description", unique = true, nullable = false, length = 20)
       @NotNull
       @Length(max = 20)
       public String getDescription()
       {
       return this.description;
       }
      
       public void setDescription(String description)
       {
       this.description = description;
       }
      
       @Transient
       public Date getStartDate()
       {
       Calendar startCal = Calendar.getInstance();
       // Determine start of week
       if (getDescription() == null || getDescription().equals("Weekly"))
       {
       System.out.println("Weekly timeline");
       }
       else if ( getDescription().equals("Monthly"))
       {
       System.out.println("Monthly timeline");
       }
       // Convert calender to date
       Date startDate = startCal.getTime();
       return startDate;
       }
      
       @Transient
       public Date getEndDate()
       {
       Calendar startCal = Calendar.getInstance();
       if (getDescription() == null || getDescription().equals("Weekly"))
       {
       ...........
       }
       return endDate;
       }
      }
      
      


      The ajax support tag calls the timelinechangelistener which sets the selected timeline and puts it into a session scope. Since the rendered element calls the selected timeline getStartDate method, I expected the selected timeline to get passed in, however the timeline on which the getStartDate is called is never selectedTimeline. Hopefully, made things clear as to what I am trying to accomplish. In short, based on the selected timeline, I would like to change the start date/end date logic.

      Any help is appreciated....

      Thanks
      Amit Karandikar


        • 1. Re: Problem with entity in session scope and JSF inputText
          pmuir

          For a start you aren't accessing TimelineChangeListener in a way in which Seam can intercept calls (so the @Out won't happen). Use a EL binding #{foo.timelineChangeListener} instead.

          • 2. Re: Problem with entity in session scope and JSF inputText
            amitdk

            Thanks.That worked - where can I find this information? I've been looking through the docs and unable to find such specifics.

            Another problem(though it may not be the right place for the post) I am noticing is that the ajax call to rerender the inputText field does not evalualte the EL expression - selectedTimeline.startDate
            unless inputText is set for disabled= true. Anyone come across this?

            - Amit