2
我有一個帶有按鈕和標籤的JSF頁面。當用戶按下simulateYearButton
按鈕時,標籤yearLabel
中顯示的值應遞增。在JSF(Primefaces)中更新標籤
與按鈕和標籤的形式如下:
<h:form>
<p:commandButton value="Заресетить" id="resetButton"
actionListener="#{entryPage.resetButtonAction}" />
<p:commandButton value="Просимулировать год" id="simulateYearButton"
actionListener="#{entryPage.simulateYearButtonAction}">
<f:ajax event="click" render="yearLabel" />
</p:commandButton>
<h:outputLabel id="yearLabelLabel" for="yearLabel" value="Год:" />
<h:outputLabel id="yearLabel" value="#{entryPage.yearLabel}"
style="font-weight:bold" />
</h:form>
守則entryPage
豆:
@ManagedBean(name = "entryPage")
@RequestScoped
public class EntryPageController {
...
private int year;
private String yearLabel;
@PostConstruct
public void init()
{
this.yearLabel = "2012";
}
...
public void simulateYearButtonAction() {
LOGGER.debug("EntryPageController.simulateYearButtonAction");
this.year++;
this.yearLabel = Integer.toString(this.year);
}
public String getYearLabel() {
return yearLabel;
}
}
當我按下simulateYearButton
,執行方法simulateYearButtonAction
(我見輸出中的日誌消息),但標籤未更新。
我應該如何修改代碼,以便在按下按鈕時更新標籤?
製作TI ViewScoped,SessionScope巨大矯枉過正只是一個拉貝:-) –
我與彼得同意 –