当我点击按钮时,重新初始化当前月份名称

时间:2011-01-07 02:30:29

标签: jsf calendar initialization richfaces

在我的 richCalendar.jsp 页面中,首次点击 showCurrentMonth 按钮,并使用rich:calendar显示当前月份。
我选择其他一些月份 我点击 SelectedMonth 按钮。我显示所选的月份名称。

我的问题是: 我去任何其他页面。然后我来访问richCalendar.jsp并再次单击 showCurrentMonth 按钮,这次rich:calendar显示已选择的月份而不是当前月份。
每次,当我点击 showCurrentMonth 时,我想显示当前月份。

否则很简单,一旦我点击 showCurrentMonth 按钮,然后我选择其他一些月, 然后我点击 showCurrentMonth 按钮,我想显示当前月份名称。

richCalendar.jsp

<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;

公共类CalenderBean {

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;
}
}

我第一次访问此页面时,完美地显示当前月份。然后我去任何其他页面然后来看这个页面,点击 showCurrentMonth 按钮不显示当前月份。

帮帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试从日历控件中删除popup = "false"。它会按你的意愿工作。

不知道这种奇怪行为的原因,但我猜有一些渲染问题。