This strange behavior only occurs in Firefox (specifically Firefox 8). Therefore, I have a dataTable , which I can do multiple selection . A submit button that displays a list of selected items in and dataList . If the user hasnโt selected anything, an msg error message appears asking the user to select something. A dialog will not appear if the user has not selected anything. This code does it all. However, FireFox behaves strangely if you follow these steps:
- Click to select an item on
dataTable - Then refresh the page (F5 or Ctl + R) on the page (you can see that the selection is cleared)
- Then click "Submit", it will show everything that I just selected.
This is uninteresting since the update should clear everything that you just select due to the nature of the @ViewScoped bean. This behavior is observed only in Firefox. IE 8 behaves right for me. Is this a mistake, or am I doing something wrong here?
Mojarra 2.1 + PrimeFaces3.0 Final + Tomcat 7
UPDATE I did some debugging when I refresh the page, the value of the selectedFoods array becomes null , but for some odd reason, when it reaches public void checkSelection() , it hold the value of the previous selection. So strange.
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" 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>
Here is my driven bean
@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"); } }
source share