1

我想用会话范围做一些类似于查看范围的东西。我有一个会话 bean,在我的页面中我有一些搜索结果表,我想清除它们并在页面加载时清除输入文本,我不能从会话 bean 更改为请求 bean,我现在唯一的想法是在页面上添加一个清除按钮,它的操作方法将重置表格和输入文本。

我正在使用jsf 1.1,请告知最好的方法。

4

1 回答 1

3

Check if the request is a GET request (or, at least, not a POST request).

HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();

if ("GET".equals(request.getMethod())) {
    // ...
}

On JSF 1.2, you'd have used ResponseStatemanager#isPostback() for this.
On JSF 2.x, you'd have used FacesContext#isPostback() for this.

You could perform this in a getter of a (hidden) output component.


A completely different alternative is to install Tomahawk and use <t:saveState> to simulate the JSF 2.x view scope on a request scoped bean.

于 2013-06-15T19:54:46.090 回答