ボタンとラベルのあるJSFページがあります。ユーザーがsimulateYearButton
ボタンを押すと、ラベルに表示されている値yearLabel
がインクリメントされます。
ボタンとラベルのあるフォームは次のようになります。
<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
Beanのコード:
@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
は実行されますが(出力にログメッセージが表示されます)、ラベルは更新されません。
ボタンを押したときにラベルが更新されるようにコードを変更するにはどうすればよいですか?