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

UI Components for JSF
breilly
Posts: 8
Joined: 09 Jan 2012, 15:58

09 Jan 2012, 16:35

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

breilly
Posts: 8
Joined: 09 Jan 2012, 15:58

09 Jan 2012, 16:53

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

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

09 Jan 2012, 18:31

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 Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

09 Jan 2012, 20:57


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

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

10 Jan 2012, 16:27

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

Code: Select all

<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>

Code: Select all

@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

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Jan 2012, 16:31

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.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Jan 2012, 23:08

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

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

10 Jan 2012, 23:21

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

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

12 Jan 2012, 16:40

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

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Jan 2012, 16:44

There is no hidden input in select one menu.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests