2017-01-30 86 views
0

我正在使用PrimeFaces SelectOneMenu更改事件调用。 当我更改它的值时,更改方法会调用并设置一些参数。当我刷新页面时,在bean侧,选中的值更改为默认值,但在UI中显示更改的值。所以,当用户点击提交时,setter方法更改值,但更改方法不会调用。 这里是UI代码:Primefaces selectOneMenu在页面刷新后更改值firefox

<p:selectOneMenu value="#{bean.selectedType}"> 
    <f:selectItems value="#{bean.types}"/> 
    <p:ajax event="change" listener="#{bean.changeType}" update=":form"/> 
</p:selectOneMenu> 
<p:commandButton actionListener="#{bean.changeType}" update=":form"/> 
+0

你找到解决问题的办法的网页?在这里与同样的问题挣扎 - .- – JokerTheFourth

回答

2

I使用remoteCommand组件解决此问题,在页面刷新后更新selectOneMenu。不要忘记在@PostConstruct方法中将选定变量设置为null。

该问题只发生在Firefox浏览器上。

代码:

<p:remoteCommand name="rcName" 
       update="@form" 
       autoRun="true" 
       ignoreAutoUpdate="true" />code 
+0

我试过了;仍然不起作用。 – hamid147

+1

嗯...您在@PostConstruct方法中将选定变量设置为null吗? – JokerTheFourth

+1

它的工作。只需将您的评论添加到您的接受答案。谢谢。 – hamid147

0

检查,如果你的bean是@RequestScoped。如果是这样,请将其更改为@ViewScoped

+0

不,它是@ViewScoped。 – hamid147

0

你试过把process="@this"放在ajax组件中吗?

+0

我试过了;仍然不起作用。 – hamid147

0

最近我有同样的问题,并能够通过添加明确的无缓存指令到HTTP标头,以解决这个问题。

例如实现javax.servlet.Filter类并执行类似于

HttpServletResponse httpServletResponse = (HttpServletResponse) response; 

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

doFilter()方法。

然后,只需应用您的过滤器类要在web.xml中筛选