2017-01-30 85 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中篩選