<p:selectOneMenu>, filter and converter - primefaces

I have a menu with filter on. The value and label are both String. In this case, does the "converter" property have to be set? The reason I'm asking is that the filter function is not working if the "converter" is not provided. E.g.,
<p:selectOneMenu value="#{menuBean.selectedCountry}" filter="true" filterMatchMode="startsWith">
<f:selectItem itemLabel="Select One" itemValue=""/>
<f:selectItem itemLabel="US" itemValue="1"/>
<f:selectItem itemLabel="Spain" itemValue="2"/>
</p:selectOneMenu>
Thank you for your points and help!

You didn't specify your primefaces version but this is a bug in 3.4. You can set the height attribute of p:selectOneMenu or you can apply the following fix from here. SelectOneMenu with filter not working with less than 10 elements.

Related

Uncheck all p:selectManyCheckbox checkboxes from a p:selectOneRadio item

How could I Uncheck all checkboxes from selectManyCheckbox when choosing "No" from selectOneRadio
<p:selectOneRadio id="radio" value="#{myView.myObject.myBoolean}">
<f:selectItem itemLabel="Si" itemValue="#{true}"/>
<f:selectItem itemLabel="No" itemValue="#{false}"/>
<p:ajax process="radio" event="valueChange" update="#widgetVar(displayPanel)"/>
<p:ajax update="#this"/>
</p:selectOneRadio>
<p:panel widgetVar="displayPanel">
<p:outputPanel rendered="#{myView.myObject.myBoolean}">
<p:selectManyCheckbox widgetVar="mySelections" value="#{myView.myObject.myObjectList}" layout="grid" columns="8" styleClass="grid-checkbox">
<p:ajax update="#this"/>
<f:selectItems value="#{myView.things}" var="thing" itemLabel="#{thing.idThing}" itemValue="#{thing.thing}"/>
</p:selectManyCheckbox>
</p:outputPanel>
</p:panel>
As seen, update="#widgetVar(displayPanel)" will show the outputPanel when myBoolean is true and viceversa.
What I need to achieve is to uncheck all the already selected checkboxes (mySelections) when myBoolean is false (by selecting "No" from selectOneRadio above.
Possible? If so, Could you please show me how, I'm just starting on PrimeFaces.
Normally, the easiest way would be using the client side API uncheckAll. However, there is a bug. But, I've fixed it. So you can wait for PrimeFaces 12.0.0-RC3 or create a Monkey Patch.
A simple demo would be:
<p:selectOneRadio id="radio" value="#{testView.bool}"
onchange="if(this.value==='false'){PF('mySelections').uncheckAll()}">
<f:selectItem itemLabel="Si" itemValue="true"/>
<f:selectItem itemLabel="No" itemValue="false"/>
</p:selectOneRadio>
<p:selectManyCheckbox widgetVar="mySelections" value="#{testView.strings}">
<f:selectItems value="#{['a','b','c']}"/>
</p:selectManyCheckbox>
This eliminates the need to use Ajax.

Applying different style to noSelectionOption on PrimeFaces SelectOneMenu

PrimeFaces p:selectOneMenu items has a property called noSelectionOption which is basicly selected when no option is selected.
I would like my p:selectOneMenu to look a bit different when a value is selected or not, but nothing in HTML change on the DOMElement of the p:selectOneMenu when the noSelectionOption option is selected or not.
Any idea ?
I don't see what you've missed, but the CSS class ui-noselection-option is applied to the list item (li) of the no select option. Tested with:
<p:selectOneMenu>
<f:selectItem itemValue="0" itemLabel="0" noSelectionOption="true"/>
<f:selectItem itemValue="1" itemLabel="1"/>
<f:selectItem itemValue="2" itemLabel="2"/>
</p:selectOneMenu>
This now leaves you with How do I override default PrimeFaces CSS with custom styles?
For example:
.ui-noselection-option {
color: red;
}

SelectOneMenu width not work use bootstrap

This is the second post on the same subject, since the first time I did not get the result. The select width problem continues.
I'm using selectOneMenu JSF 2 and trying to change the width of it is not working.
<h:selectOneMenu style="width:280px" styleClass="selectpicker"`>
<f:selectItem itemValue="1" itemLabel="A" />
<f:selectItem itemValue="2" itemLabel="B" />
<f:selectItem itemValue="3" itemLabel="C " />
</h:selectOneMenu>
Only works when I remove the styleClass = "selectpicker"
I've already tried adding the data-width, it also did not work. Any tips?
You can make your style more important by adding !important to the tag. This is usually a bad idea for maintainability.
style="width:280px !important"
Improve it like this
style="height: 46px"

jsf standard converter along with primefaces select one menu

When the "select" option of the select one menu is selected, the default value is saved in DB as 0. Can I change this to null?
The value of select one menu is bound to a bean property. To achieve this, I have used the converter attribute of the select one menu component. But it does not seem to convert empty string to null. What am I missing?
<p:panelGrid columns="2" >
<p:outputLabel value="District" />
<p:selectOneMenu value="#{cJData.cJ.dC}" converter="javax.faces.Long">
<p:ajax listener="#{cJActionHandler.selectDC}"/>
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItems value="#{cJData.DCs}" var="coun"
itemLabel="#{coun.name}" itemValue="#{coun.id}" />
</p:selectOneMenu>
</p:panelGrid>
Use the following
<f:selectItem itemLabel="Select" itemValue="#{null}" />
As the docs of LongConverter#getAsObject say - this is the method which is called when you submit th value - the Long converter will convert only null to null.

Issue in selectOneMenu in primefaces?

I am using primefaces 3.2 and i have used selectOneMenu from primefaces.When i drag and drop somethine into the selectOneMenu box it displaying some url(for example drag and drop the image into the selectOneMenu).Text box allows that drag and drop but why selectOneMenu.How to avoid that.
<p:selectOneMenu value="#{buttonBean.number}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Option 1" itemValue="1" />
<f:selectItem itemLabel="Option 2" itemValue="2" />
<f:selectItem itemLabel="Option 3" itemValue="3" />
</p:selectOneMenu>
Primefaces 3.2 uses an html input to display the selected value.
If you can, update to 3.4. The helper input is gone, no this issue.
You can test it in the showcase.