JSF问题,带有后退按钮 [英] JSF issue with back button

查看:105
本文介绍了JSF问题,带有后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用后退按钮时遇到了问题,没有将数据保留在请求范围内的JSF中的动态下拉列表中.

I'm having an issue with the back button, not keeping data in a dynamic dropdown in JSF on a request scoped bean.

我有一个包含2个下拉菜单的表单,其中dropdown2是动态的,基于dropdown1中选择的内容.以下是这些下拉菜单的代码.

I have a form with 2 dropdowns where dropdown2 is dynamic based on what is selected in dropdown1. Below is my code for these dropdowns.

<h:selectOneMenu id="group" label="group" value="#{queryBacking.groupInternalId}">
    <f:ajax event="valueChange" render="membership" />
    <f:selectItems value="#{supportBean.groupInstitutions}" var="group" itemValue="#{group.institutionInternalId}" itemLabel="#{group.institutionName}" />
</h:selectOneMenu>

<h:selectOneMenu id="membership" label="Membership" value="#{queryBacking.institutionInternalId}">
    <f:selectItem itemLabel="Select One" itemValue="0" />
    <f:selectItems value="#{queryBacking.groupMembershipInstitutions}" var="institution" itemValue="#{institution.institutionInternalId}" itemLabel="#{institution.institutionShortName}" />
</h:selectOneMenu>

我的代码非常有用,除了如果您提交表单然后单击后退"按钮,dropdown2不包含任何值.如何解决此问题?

My code works great except that if you submit the form and then click the back button, dropdown2 does not contain any values. How can fix this issue?

推荐答案

您是说浏览器中的后退按钮对吗?

You mean the back button in the browser right?

浏览器可能会将页面从浏览器缓存中加载出来.因此,您需要使用过滤器禁用缓存:

The browser probably loads the page out of the browser cache. So you need to disable caching with a filter:

public class NoCacheFilter implements Filter {
    private FilterConfig config;

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        HttpServletRequest httpReq = (HttpServletRequest) request;
        HttpServletResponse httpRes = (HttpServletResponse) response;

        if (!httpReq.getRequestURI().startsWith(
                httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { 

            httpRes.setHeader("Cache-Control",
                    "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            httpRes.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            httpRes.setDateHeader("Expires", 0); // Proxies.
        }

        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        config = null;
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
        this.config = config;
    }
}

然后将其添加到web.xml:

And then add this to the web.xml:

<filter>
  <filter-name>NoCacheFilter</filter-name>
  <filter-class>yourpackage.NoCacheFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>NoCacheFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

您可以在<url-pattern> </url-pattern>

这篇关于JSF问题,带有后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆