6 Replies Latest reply on Apr 19, 2010 11:18 AM by pavan.pavankkotturi.kumar.gmail.com

    how to write code for displaying the current time through XHTML page

    pavan.pavankkotturi.kumar.gmail.com

      Hii, Everybody
       
               please any one can give suggestions on displaying the current time by using XHTML page.


      Is there an example on seam folder regarding this one.


      Any suggestion appreciable.
      Thanking You in advance.

        • 1. Re: how to write code for displaying the current time through XHTML page
          thokuest

          Try could try this for example:



          • components.xml



          <component name="now" scope="event" auto-create="true" class="java.util.Date" />




          • using @Factory as alternative to components.xml



          @Factory(scope=ScopeType.EVENT, autoCreate=true)
          public Date getNow() {
              return new Date();
          }




          • xhtml



          <h:outputText value="#{now}">
              <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss z" />
          </h:outputText>



          Hope that helps!

          • 2. Re: how to write code for displaying the current time through XHTML page
            pavan.pavankkotturi.kumar.gmail.com
            Thanks for your suggestion, This one also working properly but it was not storing into the database.

            and one more question is,

            what i want is , while clicking on the link or button then that time only it will show the current time on that appropriate box.



            format is like this:

            _start time:_

            _end time:__

            Thanks in advance.
            • 3. Re: how to write code for displaying the current time through XHTML page
              thokuest

              Please describe what you want to achieve as exactly as possible.


              -


              Do not double post (Displaying the current time fron XHTML page)

              • 4. Re: how to write code for displaying the current time through XHTML page
                pavan.pavankkotturi.kumar.gmail.com

                Hai ,
                         I am developing the project on PROJECT MANAGEMENT by using seam frame work, on that one what I want is, I wish to enter task starting time and ending time.


                         While clicking on those corresponding text boxes it'll accept the current time.


                This one really I want.This is urgent to me.


                Thanks once again.
                 

                • 5. Re: how to write code for displaying the current time through XHTML page
                  thokuest

                  OK, I think I know what you want to achieve. Here is simple example (project generated by JBoss Tools) which should help you.


                  Task Entity




                  @Entity
                  public class Task implements Serializable {
                      private static final long serialVersionUID = 1L;
                       
                      private Long id;
                      private Integer version;
                      private String name;
                      private Date startTime;
                      private Date endTime;
                       
                      @Id
                      @GeneratedValue
                      public Long getId() {
                          return id;
                      }
                  // getters and setters



                  TaskHome



                  The interesting parts here are the methods startTask and endTask which set the start and end time.


                  @Name("taskHome")
                  public class TaskHome extends EntityHome<Task> {
                      private static final long serialVersionUID = 1L;
                       
                      @RequestParameter
                      Long taskId;
                  
                      @Override
                      public Object getId() {
                          if (taskId == null) {
                           return super.getId();
                       } else {
                           return taskId;
                       }
                      }
                  
                      @Override
                      @Begin
                      public void create() {
                       super.create();
                      }
                  
                      public void startTask() {
                       this.instance.setStartTime(new Date());
                      }
                       
                      public void endTask() {
                          this.instance.setEndTime(new Date());
                      }
                  }



                  task.xhtml



                  Look at the a4j:commandButtons startTask and startTask.


                  <h:form id="taskForm">
                      <a4j:outputPanel ajaxRendered="true">
                          <rich:panel>
                              <f:facet name="header">task</f:facet>
                       
                              <s:decorate id="nameField" template="layout/edit.xhtml">
                                  <ui:define name="label">Name</ui:define>
                                  <h:inputText id="name" required="true"
                                      value="#{taskHome.instance.name}"/>
                              </s:decorate>
                                   
                              <s:decorate id="startTimeField" template="layout/edit.xhtml">
                                  <ui:define name="label">Start Time</ui:define>
                                      <h:outputText id="startTime" value="#{taskHome.instance.startTime}">
                                          <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" />
                                      </h:outputText>
                              </s:decorate>
                                   
                              <s:decorate id="endTimeField" template="layout/edit.xhtml">
                                  <ui:define name="label">End Time</ui:define>
                                  <h:outputText id="endTime" value="#{taskHome.instance.endTime}">
                                      <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" /> 
                                  </h:outputText>
                              </s:decorate>
                                   
                              <div style="clear:both"/>
                          </rich:panel>
                       
                          <div class="actionButtons">
                              <a4j:commandButton id="startTask" 
                                  value="Start Task"
                                  action="#{taskHome.startTask}"
                                  disabled="#{not empty taskHome.instance.startTime}" />
                              <a4j:commandButton id="endTask" 
                                  value="End Task"
                                  action="#{taskHome.endTask}"
                                  disabled="#{empty taskHome.instance.startTime or not empty taskHome.instance.endTime}" />
                                    
                          <h:commandButton id="save"
                                  value="Save"
                               action="#{taskHome.persist}"
                               rendered="#{not taskHome.managed}"
                               disabled="#{empty taskHome.instance.endTime}"/>
                          <h:commandButton id="update"
                               value="Save"
                               action="#{taskHome.update}"
                               rendered="#{taskHome.managed}"/>
                          <h:commandButton id="delete"
                               value="Delete"
                               action="#{taskHome.remove}"
                               immediate="true"
                               rendered="#{taskHome.managed}"/>
                          <s:button propagation="end"
                               id="cancel"
                               value="Cancel"
                               view="/taskList.xhtml"/>
                          </div>
                      </a4j:outputPanel>
                  </h:form>

                  • 6. Re: how to write code for displaying the current time through XHTML page
                    pavan.pavankkotturi.kumar.gmail.com

                    Thanks for your reply,this one only exactly I want.


                    It was working properly, and showing the start time and end time.


                    Now, that the problem is it was not stored in the database.


                    Can you please provide the complete code regarding to this one.