Take the 2-minute tour ×

This odd behavior only happen in Firefox (specifically Firefox 8). So I have a dataTable that I can do multiple selection. A submit button, that will display a list of selected items to a dataList and to a dialog. If the user did not select anything, then a error msg come up asking the user to select something. The dialog will not appear if the user select nothing. The below code does all that. However FireFox behaves oddly if you do these follow:

  1. Click to select an item on the dataTable
  2. Then refresh (F5 or Ctl + R) the page (you can see the selection got clear off)
  3. Then click submit, it show whatever I just selected.

This is unexpecting, since the refresh should clear out whatever you just select due to nature of @ViewScoped bean. This behavior only happen in Firefox. IE 8 behave correctly for me. Is this a bug, or am I doing something wrong here?

Mojarra 2.1 + PrimeFaces3.0 Final + Tomcat 7

UPDATE: I did some debugging, when I refresh page, the value of the array selectedFoods become null, but for some odd reason, when it get to public void checkSelection(), it hold the value of the previous selection. So odd.

Here is my code.

<p:growl id="messages" showDetail="true" />  
<p:messages id="msgs"/>
<h:form id="form">  
    <p:dataTable value="#{viewBean.foodList}" var="item" 
        <f:facet name="footer">
            <p:commandButton value="Submit" update=":form:display :dataList" 
    <p:dataList id="display" value="#{viewBean.selectedFoods}" var="item"
<p:dialog id="dialog1" widgetVar="dialog1" dynamic="true" width="200">
    <p:dataList id="dataList" value="#{viewBean.selectedFoods}" var="item"

Here is my managed bean

public class ViewBean implements Serializable {
    private List<String> foodList;
    private String[] selectedFoods;

    public void init() {
        foodList = new ArrayList<String>();

    public void checkSelection(){
        RequestContext requestContext = RequestContext.getCurrentInstance();
        if(selectedFoods.length > 0){
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Error", "Please select"));
    //setter, getter
share|improve this question
:P If your code can run correctly on some browser, I would say that you didn't do anything wrong. If your server-side code is wrong somewhere, it will appear on all browser ^^ –  Mr.J4mes Jan 6 '12 at 20:58
@Mr.J4mes :D I was wondering if you generate the same result as I did? –  Thang Pham Jan 6 '12 at 21:13
I still haven't tried yet but I will later :P –  Mr.J4mes Jan 6 '12 at 21:21
FWIW: can't reproduce on FF9. I don't have FF8 at hands. –  BalusC Jan 8 '12 at 3:32

1 Answer 1

Your code is fine. What you're seeing is because of something that is supposed to be a feature of Firefox (I was able to reproduce this on FF4). The selection model for p:dataTable is implemented with a hidden form field. When reloading a page, Firefox tries to save and restore form field values that have changed so that you don't lose what you entered. You can observe this by adding a <h:inputText/> to your view, typing something in the input, and reloading.

I'm not sure that the Firefox team meant for this to apply to hidden form fields, but I figure there's a decent chance that they did. I plan to file a bug report with Primefaces to either initialize the hidden input or to read the input on load to make the p:dataTable selection match. Either solution should result in the rendered selection and the hidden selection model to be in sync.

share|improve this answer
Thank you so much for your explanation. I would really appreciated if you can file a bug report to PrimeFaces. –  Thang Pham Jan 9 '12 at 14:13
Ah right, that field should have an autocomplete="off". @Harry: you can just report yourself as well on code.google.com/p/primefaces/issues –  BalusC Jan 9 '12 at 14:14
I went to file the report and it wanted a forum topic to reference, so I posted there: forum.primefaces.org/viewtopic.php?t=17425. I'll have to learn more about autocomplete as it sounds like that's probably the right solution. –  Brian Jan 9 '12 at 14:39
@BalusC: I have submit issue report for PF at code.google.com/p/primefaces/issues/detail?id=3263. Thank you guys –  Thang Pham Jan 9 '12 at 18:57

Your Answer


