当我使用<h:outputText>
in 时<p:panelGrid>
,getter 属性getStartDate()
并getEndDate()
不起作用。但是,当我<p:panelGrid>
从页面中删除时,getter
属性运行良好。还有一件事,当我点击链接时,我得到了in action 方法Go To Next Week
的 null 值。我不知道为什么,即使我使用as 。endDate
nextWeek()
DatePick
Conversation Scope
我的页面.xhtml
<table>
<tr>
<td>
<p:commandLink action="#{DatePick.nextWeek()}" immediate="true" value="Go To Next Week" />
</td>
</tr>
<tr>
<td colspan="2">
<p:panelGrid style="margin-top:-1px;" id="datePanel">
<h:outputText value="#{DatePick.startDate}" style="color:#333333;font-size:15px;">
<f:convertDateTime pattern="yyyy-MM-dd"/>
</h:outputText>
-
<h:outputText value="#{DatePick.endDate}" style="color:#333333;font-size:15px;">
<f:convertDateTime pattern="yyyy-MM-dd"/>
</h:outputText>
</p:panelGrid>
</td>
</tr>
</table>
日期选择.java
@Name("DatePick")
@Scope(ScopeType.CONVERSATION)
public class DatePick {
private Date startDate;
private Date endDate;
private boolean initFlag = true;
public void init() {
System.out.println("init().....");
initFlag = false;
startDate = new Date();
}
public boolean getInitFlag() {
System.out.println("getInitFlag() : " + initFlag);
return initFlag;
}
public Date getEndDate() {
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
cal.add(Calendar.DATE, 7);
endDate = cal.getTime();
System.out.println("getEndDate() : " + endDate);
return endDate;
}
public Date getStartDate() {
System.out.println("getStartDate() : " + startDate);
return startDate;
}
public void nextWeek() {
System.out.println("nextWeek() : " + endDate);
startDate = endDate;
}
}