Board index JavaServer Faces General p:dataTable selection model gets out of sync after reload in

p:dataTable selection model gets out of sync after reload in

Components, Ajax Framework, Utilities and More.


Posts: 8
I believe I found a bug with p:dataTable while investigating a question on StackOverflow (http://stackoverflow.com/questions/8764 ... ean-even-a). The issue is that, when reloading a page, Firefox tries to save changed form values and restore them after reload so that the user does not lose what they entered. Since p:dataTable uses a hidden form element to keep track of the selection, Firefox restores this value. This leads to the rendered selection and the actual selection being different.

I think that the p:dataTable component should either explicitly clear out the hidden input or read the value and render the selection in the table to reflect the hidden input. I personally tested this on FF4 (Mac OS X) and the original reporter said that they'd seen it on FF8, though someone else followed up saying that they didn't see it on FF9.

Thanks.
PrimeFaces 3.4.1, Mojarra 2.1.7, JBoss AS 7.1.1


Posts: 8
Update: a further comment on StackOverflow suggests adding autocomplete="off". Sounds like adding this to the hidden input would also fix the problem. Thanks.
PrimeFaces 3.4.1, Mojarra 2.1.7, JBoss AS 7.1.1

Oleg User avatar
Expert Member

Posts: 3702
Location: Russia, Siberia => Germany, Black Forest
Yes, this is a Firefox "feature". There are many links about this.

http://alexscordellis.blogspot.com/2010 ... -with.html
http://stackoverflow.com/questions/6487 ... -auto-fill

Just interesting why PrimeFaces doesn't have autocomplete="off" for hidden fields. I think other components are affected too. I could see this issue in 2.2.1. Please create an issue ticket.
PrimeFaces 4.x, 5.x, Mojarra 2.2.x, JBoss WildFly, WebSphere, Windows 8.1, IntelliJ IDEA
PrimeFaces Cookbook: http://ova2.github.com/primefaces-cookbook/ PrimeFaces Extensions on GitHub: http://primefaces-extensions.github.com/


Posts: 280

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 280
Oddly, I can still replicate this under FF9. Can anyone try this code and see if they can replicate this? Thanks in advance. PF 3 Final + tomcat 7

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



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

    @PostConstruct
    public void init() {
        foodList = new ArrayList<String>();
        foodList.add("Pizza");
        foodList.add("Pasta");
        foodList.add("Hamburger");
    }

    public void checkSelection(){
        RequestContext requestContext = RequestContext.getCurrentInstance();
        if(selectedFoods.length > 0){
            requestContext.execute("dialog1.show()");
        }else{
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Error", "Please select"));
            requestContext.addPartialUpdateTarget("messages");
        }
    }
    //setter, getter
 }


Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 15043
Location: Cybertron

Try setting autocomplete off to the hidden field and let me know if it fixes the issue, if so we can add it to PrimeFaces. To do this, you need to know how to build PF from source for a local test.
PrimeFaces Lead


Posts: 15043
Location: Cybertron

I have added autocomplete off to trunk, you can try with the build from repo to see if it fixes your issue.
PrimeFaces Lead


Posts: 280
Thank you Optimus, I will do it as soon as I get home. Thanks a lot.

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 280
Hi Optimus, sorry that it took me two days to test this out, but I have compile the latest SNAPSHOT, and it seems like remove autocomplete fix this problem. Thank you. I also notice that p:selectOneMenu suffer from the same problem. You can test at http://www.primefaces.org/showcase-labs ... neMenu.jsf. Select one item in the drop down, and refresh. On chrome and IE, the drop down value reset back to "Select One", but on Firefox, it retain this value. Anyway, I will make this a separate post.

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 15043
Location: Cybertron

There is no hidden input in select one menu.
PrimeFaces Lead

Next

Return to General