Primefaces 6.1 SelectOneMenu pick itemLabel as value - primefaces

I am using PrimeFaces 6.1 SelectOneMenu to render a editable/filtered dropdown menu with itemLabel/value as selectItems. Unfortunately, selectOneMenu pick itemLabel as value put it in my selectOneMenu value field. This is very annoying issue and maybe it is a bug.
There is my snippet code:
I am using Map to hold ID/Name pair as selectItems:
Map<String,String> hm = new HashMap<String, String>();
hm.put("Cust001","John Dow");
hm.put("Cust002","Mark Polo");
hm.put("Cust003","Noel Max");
then I put it in my selectOneMenu as:
<p:selectOneMenu id="selectCustomerId" value="#{paymentControlBean.selectedCustomerId}" effect="fold" editable="true" filter="true" filterMatchMode="startsWith">
<p:ajax update="paymentListToolbar"/>
<f:selectItems value="#{hm.entrySet()}" var="entry" itemValue="#{entry.key}" itemLabel="#{entry.value}"/>
</p:selectOneMenu>
Dropdown list rendering works fine, but when I pick one from the dropdown list and then press process it. My backing bean paymentControlBean.selectedCustomerId shows up "John Dow", which means, selectOneMenu pick my itemLabel into my selectOneMenu's value field.
I tried to change the PrimeFaces element to p:selectOneListBox and keep everything no change, repeat the processing, my backing bean shows up "Cust001", which is working fine.
From this comparison I found out, there must a serious bug exists in PrimeFaces 6.1, and it is same bug existing in PrimeFaces 5.2 as well.
SelectOneMenu is very popular in dropdown list selection, especially when we have to handle key/value pairs by using Map.
If it is not a bug, what I can do or have an other work around to make it pick up right value in my selectItems?
Please advise>

I have fixed it with this PR: https://github.com/primefaces/primefaces/pull/2870
It will be in PrimeFaces 6.2 release coming out in November 2017.

Related

Primefaces inputNumber emptyValue="empty" is not empty

JSF 2.2
Primefaces 6.0
The "emptyValue" attribute of p:inputNumber seems straightforward, and yet it is not working
<p:inputNumber id="wsMaxInput" emptyValue="empty"
value="#{officeResults.wsCountMax}" maxValue="3000"
minValue="0" styleClass="ondInput" />
Not only does it not look empty (I'm not sure if picture attaching will work from here), but when I hit "submit" the value is set to zero when it should be null.
What am I missing about this component?

p:selectOneMenu using a mask in 'editable' mode

The following works
<p:selectOneMenu value="#{f.entrada1}" editable="true">
As does
<p:inputMask mask="99:99" value="#{f.saida1}">
I do not seem to be able to combine the two in some way or add a mask to the editable p:selectOneMenu in a different way?
My PrimeFaces version is: ....
Version PrimeFaces 5.3.
Or put a list in inputMask. it's possible?

primefaces selectManycheck box columns attribute is not working

I am using Primefaces 3.5, as shown in showcase, i am trying to use p:selectManyCheckBox.
<p:selectManyCheckbox layout="grid"
columns="2"
value="#{bean.selectedList}">
<f:selectItems itemLabel="#{bean.value}"
itemValue="#{overrides}"
value="#{bean.overrideValues}"
var="overrides>
</p:selectManyCheckbox>
But columns attribute is not working, is there any way to get column wise disply ?
I had the same problem and I fixed by changing the version of the prime face.
I had 3.2 and changed to 4.0.
For this particular component it seams that it whose added in the last 2 moth.
Requested here and a specific task here.
Is the second time when I also had this kind of problem. I am looking on the prime face showcase website for a specific component and and when I tried that component it didn't work with my version.

PrimeFaces PickList : two String fields filter

I was wondering if it's possible to have a two fields filter with a picklist of primefaces.
I tried this but it's not working. I would like to filter on firstname and name but they are in two different fields.
<p:pickList value="#{bean.usersDualModel}" var="user"
itemValue="#{user}" itemLabel="#{user.firstname} #{user.name}"
converter="user" showSourceFilter="true" showTargetFilter="true"
filterMatchMode="contains" >
<p:column>
<h:outputText value="#{user.firstname} #{user.name}" />
</p:column>
</p:pickList>
Thanks
In fact, I think it's possible because it's working know with the code I posted above. However, the Javascript method is easy to set up with two fields so I could have done it quickly. Thanks for the suggestion.
The reason it wasn't working the first time is that there is an bug in Primefaces for the picklist filter and it's not patched officialy. The filter mode stayed in startsWith whatever the value I entered.
So my picklist is still
<p:pickList value="#{bean.usersDualModel}" var="user"
itemValue="#{user}" itemLabel="#{user.firstname} #{user.name}"
converter="user" showSourceFilter="true" showTargetFilter="true"
filterMatchMode="contains" > ...
And there is a custom patch by know. Here is the link of the report.
https://code.google.com/p/primefaces/issues/detail?id=5234
This is not possible with the default component. However you can create a custom filter (example taken from Primefaces manual):
<p:pickList value="#{pickListBean.cities}" var="city" itemLabel="#{city}"
itemValue="#{city}" showSourceFilter="true" showTargetFilter="true
filterMatchMode="custom" filterMatchMode="myfilter">
</p:pickList>
function myfilter(itemLabel, filterValue) {
//Filter for firstname or name
//return true or false
}
Of course you can also create a custom component by extending the primefaces picklist or create two seperate inputtext fields and fire any filtering manually with javascript/jquery.

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