Primefaces selectOneMenu changes value after page refresh in firefox - primefaces

I am using PrimeFaces SelectOneMenu with change event call.
When I change it's value, the change method calls and sets some parameters. when I refresh the page, in the bean side, selected value changes to default but in the UI, changed value showed. So, when user clicks on the submit, the setter method changes the value but change method don't calls.
Here is UI code:
<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"/>

I Solve this problem with remoteCommand component, to update selectOneMenu after page is refreshed. Don't forget to set selected variable to null in #PostConstruct method.
The problem occurs only on Firefox browser.
code:
<p:remoteCommand name="rcName"
update="#form"
autoRun="true"
ignoreAutoUpdate="true" />code

I recently had the same problem and was able to solve it by adding explicit no-cache instructions to the HTTP-Header.
e.g. implement the javax.servlet.Filter class and do something like
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.
in the doFilter() method.
Then just apply your filter-class to the pages you want to filter in your web.xml

Check if your bean is #RequestScoped. If so change it to #ViewScoped.

Are you tried to put process="#this" in the ajax component?

For me, this was solved via the example in https://www.logicbig.com/tutorials/misc/primefaces/select-one-menu-with-ajax.html
The key is that the ajax change event isn't well supported (it does not appear to fire the update). Using itemSelect instead completely fixed this problem for me.
<p:ajax event="itemSelect" update="#all"/>

Related

Updating a bounded JSF attribute dynamically

i wanted to know if there is a way to update a jsf commandlink bounded attribute after the user clicks on it.
<p:commandLink resetValues="true" value= "#{NotificationManagedBean.countUnreadNotification}" actionListener="#{NotificationManagedBean.showUnreadNotification()}" />
In this case, countUnreadNotification is a number, i would like to reset the value after the user clicks on showunreadnotification...
I've tried resetting countUnreadNotification to 0 at the backing bean and refreshing the page, but to no avail. Scope for the backing bean is requestscoped.
Is there a way to do this?
The resetValues attribute is used to reset all input html element on the client before the ajax request is sent, which isn't what you want here.
And since your backing bean is requestscoped, the countUnreadNotification attribute will always be 0 since this bean will allocated from scratch for each request.
But what you aren't doing is marking the commandLink component to be updated when the ajax request returns:
<p:commandLink value="#{NotificationManagedBean.countUnreadNotification}"
actionListener="#{NotificationManagedBean.showUnreadNotification()}"
update="#this" />

Primefaces Accordion: actionListener mapped to remoteCommand not called anymore

"anymore" is definitely a key word here. I had this working, and even after comparing my previous revisions, I cannot see a smoking gun.
I have placed an accordion in the navigation panel on the West side of my layout. I have overridden the actionListener to call a remoteCommand, like this.
<p:accordionPanel widgetVar="tabPanel"
dynamic="true" cache="true"
activeIndex="-1"
actionListener="tabChange()">
<p:remoteCommand name="tabChange"
process="#this"
update=":contentPanel"
actionListener="#{viewSelectionBean.changeView}" />
When clicking on any given tab, it used to call the backing bean method changeView, which sets the html page being shown in ":contentPanel", but now I get no backing bean action. I have commandLinks within each of these accordion tabs that also call changeView successfully. Its only the tabChange() that doesn't seem to be called.
actionListener is not a property of accordionPanel, therefore, thats why it wouldn't be called. This feature can be made to work using ajax, but it demonstrates lag while expanding each tab. Lag aside, one might also have success overriding onTabChange of the accordionPanel, but that will force you to have to manually effect the activeIndex, and the expanding of tabs.
<p:accordionPanel widgetVar="tabPanel"
dynamic="true" cache="true"
activeIndex="-1">
<p:ajax event="tabChange"
listener="#{viewSelectionBean.onTabChange}"
update=":contentPanel"
process="#this"
partialSubmit="true"/>

Ajax update is not working in primefaces

i am using primefaces 3.2 when try to update the ajax in two differnt forms is not getting updated. See the below code
<p:selectOneMenu value="#{baen.vareable1}">
<f:selectItem itemLabel="val1" itemValue=="val1"/>
<f:selectItem itemLabel="val2" itemValue="val2" />
<p:ajax update="new" listner="#{bean.val()}" event="onchange"/>
</p:selectOneMenu >
replace event="onchange" with event="change" or event better remove it completely (cause its the default event)
Could it be that a form validation is blocking the request? Try setting <p:ajax process="#this" .../>.
By default the complete form that the component belongs to is processed. So by setting this attribute to "#this", only the selectOneMenu component is processed. An additional advantage is that the request becomes a little bit lighter, because less information is sent to the server.

Primefaces AJAX event not working inside tabView

How can I use an AJAX listener inside a tabview. Whenever the tab opened(or for a mouse click anywhere), the listener need to execute. I tried with event=click,change,blur etc, but not worked.
<p:tabView activeIndex="#{backingbean.tanIndex}">
<p:ajax event="?" listener="#{backingbean.setTabIndex}" />
in view.jsf:
<p:tabView>
<p:ajax event="tabChange" listener="#{employeeEdit.onTabChange}">
in edit.jsf:
<p:tabView activeIndex="#{employeeEdit.tabIndex}">
in backingBean:
private int tabIndex;
public int onTabChange(TabChangeEvent event)
{
// Here I'm getting event.getTab().getId() and set it to `tabIndex` property.
}
When editing I need redirect to the that tab which is active in view. So if I didn't change the tab onTabChange() will not execute and tabIndex has its old value only.
I'm using Primefaces version-3.0.M3.
It looks like this was a Primefaces bug that was fixed in the newest 3.0.1 release:
http://forum.primefaces.org/viewtopic.php?f=3&t=17288
I had a similar problem with Primefaces 5.1
As long as i put the tabview into a form everything worked fine.
But because i wanted to use seperate forms in my tabs i had to remove the surrounding form of the tabview to avoid nested forms.
Without the surrounding form the ajax event didn´t get triggered any more when changing the tab.
My solution was to use a remotecommand in a form parallel to the tabview.
The remotecommand is triggered by the onTabChange attribute of the tabview element.
At that call i forwarded the index parameter to the global request parameters.
<p:tabView id="rootTabMenu" styleClass="tabcontainer" prependId="false"
activeIndex="#{sessionData.activeTabIndex}" widgetVar="rootTabMenu"
onTabChange="tabChangeHelper([{name: 'activeIndex', value: index}])">
// Tabs...
</p:tabView>
<h:form id="tabChangeHelperForm">
<p:remoteCommand name="tabChangeHelper" actionListener="#{sessionData.onTabChange()}" />
</h:form>
In the backing bean i catched the value again from the request parameter map and set the active index.
public void onTabChange()
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> paramMap = context.getExternalContext().getRequestParameterMap();
String paramIndex = paramMap.get("activeIndex");
setActiveTabIndex(Integer.valueOf(paramIndex));
System.out.println("Active index changed to " + activeTabIndex);
}
Hope that can help you
Not sure if what I am writing is true for ver 3.0.M3. I have in front of the documentation of ver 3.0RC2 and there is a paragraph about this, with explaination and sample code (chapter TabView, paragraph Ajax Behaviour Events). You should have a look at that.
This is the part of the sample code that should help most:
<p:tabView>
<p:ajax event=”tabChange” listener=”#{bean.onChange}” />
</p:tabView>
Jaron has an answer that the 3.0.1 release fixed this but I had this all the way up to 3.5 i believe i was still having this problem. on firefox and IE, the javascript handler for the Tabs weren't firing the ajax event. On google chrome, for whatever reason, it actually worked.
I moved up to Primefaces 5.0 today and this does NOT have the problem any longer. So at the very worst-case, go to Primefaces 5.0 and you'll be all good in the hood

collapsing p:tree

I have a tree that is used as menu, so every node is clickable and opens another *.xhtml file. The tree is displayed on every *.xhtml file with templates.
Problem: the tree collapses if redirect to a *.xhtml file. Surprisingly, the selected node stays selected (it is colored as selected). The tree shouldn't collapse!
The tree is generated dynamic, but it is only generated once.
Tested with Primefaces 2.2.1 and 3.0.M2
How can I solve this problem? At primefaces showcase this works.
My code:
<h:form id="formTreeStudents">
<p:tree id="treeGroups"
value="#{studentTree.root}"
var="node"
cache="true"
selectionMode="single"
nodeSelectListener="#{studentTree.onNodeSelect}"
selection="#{studentrTree.selectedNode}"
onselectComplete="ajaxDialog.show();"
update="statusbar userbar">
<p:treeNode>
<h:outputText value="#{node.treeString}" styleClass="treeNodeParent"/>
</p:treeNode>
</p:tree>
<p:ajax event="load" onstart="ajaxDialog.hide();"/>
</h:form>
The bakingBean is sessionScoped. It has getter and setter similar to the example at primefaces showcase and a listener function.
#ManagedBean
#SessionScoped
public class StudentTree implements Serializable{
...
public void onNodeSelect(NodeSelectEvent event) {
...
}
}
The tree node stays selected because the property #{studentrTree.selectedNode} of the managed bean has a value.
Your managed bean is #SessionScoped so it will live in session even after you navigate away from and back to the page. If you were to change it to #ViewScoped then the managed bean will die when navigating away from the page, and when you navigate back to the page the property selectedNode will be its default value again.
solved it.
it works with Primefaces 3.0.M2. Something was wrong with my libraries or with cached data.
Some changes had to be done to use 3.0.M2.
f.e.:
nodeSelectListener="#{studentTree.onNodeSelect}"
is now replaced with
<p:ajax event="select" listener="#{studentTree.onNodeSelect}"/>