我试图addMoreStatus
通过使用 的action
属性来调用该方法<p:commandButton>
,但它没有被调用。我还使用 ajax 来查看会话变量的值是否发生变化。不幸的是,在获取更多状态中的会话变量永远不会被更新。toIndex 始终显示 5。
1)xhtml
<h:body>
<c:if test="#{statusBean.init == null}"/>
<h:form id="foo">
<p:commandButton id="bar" action="#{statusBean.addMoreStatus}"
value="test" update="test"></p:commandButton>
<h:outputLabel value="#{sessionScope['toIndex']}" id="test" />
</h:form>
</h:body>
2)状态豆
public String getInit(){
System.out.println("inside getInit");
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
int toIndex = 5;
session.setAttribute("toIndex", toIndex);
return null;
}
public void addMoreStatus(){
System.out.println("inside addMoreStatus");
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
int toIndex = (int) session.getAttribute("toIndex");
toIndex = toIndex + 5;
session.setAttribute("toIndex", toIndex);
}