7 Replies Latest reply on Dec 7, 2008 7:31 PM by valatharv

    rich:calendar, how to display current date on Create screen

    valatharv

      I need to display current date as default value in rich:calendar when the page loads on create screen.

      Please suggest how this can be achieved, any trick....

      I tried adding label="#{currentDatetime}", we need to keep value="#{projectHome.instance.projectDateElement}" as it is mapped to database column.

      Changing value="#{currentDatetime}" displays the current date on create screen.

      <s:decorate id="projectDateElementDecoration" template="layout/edit.xhtml">
      <ui:define name="label">Project Date</ui:define>
      <rich:calendar id="projectDateElement"
      value="#{projectHome.instance.projectDateElement}" datePattern="MM/dd/yyyy"/>
      </s:decorate>

        • 1. rich:calendar question pls help, how to display current date
          valatharv

          Please suggest on this, is it possible using rich:calendar

          I need to display current date as default value in rich:calendar when the page loads on create screen.

          Please suggest how this can be achieved....

          I tried adding label="#{currentDatetime}", we need to keep value="#{projectHome.instance.projectDateElement}" as it is mapped to database column.

          <s:decorate id="projectDateElementDecoration" template="layout/edit.xhtml">
          <ui:define name="label">Project Date</ui:define>
          <rich:calendar id="projectDateElement"
          value="#{projectHome.instance.projectDateElement}" datePattern="MM/dd/yyyy"/>
          </s:decorate>

          • 2. Re: rich:calendar, how to display current date on Create scr
            ilya_shaikovsky

            so just map the value of the calendar to some request scoped bean property and set default value to today. And update real binding from this bean in you action

            • 3. Re: rich:calendar, how to display current date on Create scr
              valatharv

              Hi Ilya,

              Thanks for replying, please provide any sample, it will be very helpful and I will be very thankful to you...

              Regards

              • 4. Re: rich:calendar, how to display current date on Create scr
                valatharv

                I tried this, I am able to get current date in text field, how to display in calendar, how to update real binding, please help ....

                <rich:calendar id="quantExperimentDateElement"
                value="#{quantExperimentHome.instance.quantExperimentDateElement}" datePattern="MM/dd/yyyy"/>
                <h:inputText value="#{reagentUtil.calDate}"/>

                ReagentUtil.java:
                -------------------
                public class ReagentUtil {
                private Date calDate;
                public Date getCalDate() {
                calDate = new java.util.Date();
                return calDate;
                }

                • 5. Re: rich:calendar, how to display current date on Create scr
                  ilya_shaikovsky

                  look you should define the value for the calendar as #{someTempBean.date} then for example if you use command button or support to submit the form - defined action on this component and just move the values submitted to the real bean.

                  • 6. Re: rich:calendar, how to display current date on Create scr
                    valatharv

                    Hi Ilya,

                    a) I defined the value of rich calendar as suggested by you
                    <rich:calendar id="dateElement" value="#{dateUtil.calDate}" datePattern="MM/dd/yyyy"/>

                    b) As you mentioned to move the values to actual bean..
                    We are using seam, and will have an action "Save" which will call xxxxHome.persist()

                    Did you mean to get the reference of DateUtil in actualHome then move... OR anything else...

                    Please suggest...

                    ACTUAL HOME CLASS
                    -----------------
                    @Name("xxxxHome")
                    public class xxxxHome extends EntityHome {

                    public String persist(){
                    //NEED TO GET THE DATE FROM DATEUTIL HERE TO MOVE THE VALUES
                    return super.persist();
                    }

                    DateUtil.java
                    -------------
                    public class DateUtil {
                    ....
                    public Date getCalDate() {
                    if (calDate == null)
                    calDate = new java.util.Date();
                    return calDate;
                    }

                    public void setCalDate(Date calDate) {
                    this.calDate = calDate;
                    }

                    • 7. Re: rich:calendar, how to display current date on Create scr
                      valatharv

                      Hi,

                      To update, it is working fine now, I provided the condition at entity level.

                      I think rich:calendar should have the option to display current date on pop-up....

                      Regards