1 Reply Latest reply on Jan 7, 2011 3:52 AM by Eswara MoorthyNEC

    Show current month name when i click a4j:commandbutton

    Eswara MoorthyNEC Newbie

      Hi,

      i want to disply current month name , when i click showCurrentMonth button.

       

      First time i click showCurrentMonth button it displayed current month name << < janauary 2011 > >>. Then i select << < march 2011 > >>.

      My problem is : Then i second time click showCurrentMonth button,  not show the current month name. But show the already selected month.

       

       

      <body>
       <h:form id="calendarForm" binding="#{CalenderBean.initForm}">               
         <rich:panel>                                      
           <a4j:outputPanel id="calendarOutputPanel">              
             <h:panelGrid>                                                      
                <a4j:commandButton value="showCurrentMonth" 
                                   action="#{CalenderBean.showCurrentMonthAction}"
                                   reRender="monthlyPanelGridId,monthlyCalendarId,calendarOutputPanel"/>                                                          
      
               <h:panelGrid id="monthlyPanelGridId" rendered="#{CalenderBean.monthlyCalendarRendered}" >
                 <rich:calendar boundaryDatesMode="scroll"
                                id="monthlyCalendarId" 
                                showWeekDaysBar="false"
                                oncurrentdateselected="event.rich.component.selectDate(event.rich.date)"
                                showFooter="false"
                                popup="false"
                                value="#{CalenderBean.selectedMonth}"/>
               </h:panelGrid>
      
               <h:panelGrid id = "SearchButtonGrid">
                  <a4j:commandButton id="SelectedMonth" 
                                     value="SelectedMonth"
                                     action="#{CalenderBean.selectedMonthButtonAction}"
                                     reRender="calendarOutputPanel"/>
      
                  <h:outputText value="#{CalenderBean.selectedMonthName}" />
      
               </h:panelGrid>
            </h:panelGrid>                                                               
         </a4j:outputPanel>
        <rich:panel>
       </h:form>
      </body>
      
      
      
      
      
      
      

       

      CalenderBean.java

       

      import java.util.Calendar;
      import java.util.Date;    
      import javax.faces.component.html.HtmlForm;
      
      public class CalendarBean{
      
      private HtmlForm initForm;    
      private boolean monthlyCalendarRendered;
      private Date selectedMonth;
      private String selectedMonthName;
      
      public CalenderBean()
      {
      }
      
      public String showCurrentMonthAction()
      {
          monthlyCalendarRendered = true;
      
          Calendar calendar = Calendar.getInstance();
          int startingDate = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
          calendar.set(Calendar.DATE, startingDate);
          selectedMonth = calendar.getTime();       
      
          return "";
      }
      
      public String selectedMonthButtonAction()
      {        
          selectedMonthName = selectedMonth.toString();
          return "";
      }
      
      public HtmlForm getInitForm()
      {       
          selectedMonth = null;
          monthlyCalendarRendered = false;  
      
          return initForm;
      }
      
      
      public void setInitForm(HtmlForm initForm){
          this.initForm = initForm;
      }
      
      public boolean isMonthlyCalendarRendered(){
          return monthlyCalendarRendered;
      }
      
      public void setMonthlyCalendarRendered(boolean monthlyCalendarRendered){
          this.monthlyCalendarRendered = monthlyCalendarRendered;
      }
      
      public Date getSelectedMonth(){
          return selectedMonth;
      }
      
      public void setSelectedMonth(Date selectedMonth){
          this.selectedMonth = selectedMonth;
      }
      
      public String getSelectedMonthName(){
          return selectedMonthName;
      }
      
      public void setSelectedMonthName(String selectedMonthName){
          this.selectedMonthName = selectedMonthName;
      }
      }
      
      
      
      
      
      
      
      
      
      

      Help me.

      Thanks in advance.