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

发布于 2024-10-10 23:02:53 字数 4103 浏览 2 评论 0原文

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

我的问题是: 我转到任何其他页面。然后我访问 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按钮不显示当前月份。

帮我。 提前致谢。

In my richCalendar.jsp page, first time i click the showCurrentMonth button and display the current month using rich:calendar.
i select some other month
i click SelectedMonth button. I show the selected month name.

My problem is :
I go to any other page. then i come visit the richCalendar.jsp and again click showCurrentMonth button, this time the rich:calendar show the already selected month instead of current month .
Each time, i want to show current month when i click showCurrentMonth.

Otherwise simple, once i click showCurrentMonth button, then i selecte some other month,
then i click showCurrentMonth button, i want to show current month name.

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;

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

First time i visit this page perfectly show the current month. Then i go to any othe page and then come to see this page, click showCurrentMonth button not show the current month.

Help me.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇到 2024-10-17 23:02:53

尝试从日历控件中删除 popup = "false"。它会按照你想要的方式工作。

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

Try removing popup = "false" from your calendar control. It will work as you want.

Don't know the reason for this weird behavior but I guess there is some rendering issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文