Eg:
<p:selectOneMenu value="#{UserBean.country}" id="countryId">
<f:selectItem itemLabel="Japan" itemValue="Japan"/>
<f:selectItem itemLabel="Russia" itemValue="Russia"/>
<f:selectItem itemLabel="India" itemValue="India"/>
<p:ajax listener="#{UserBean.onChangeCountry}" process="@this"/>
</p:selectOneMenu>
Like above I have many other selectOneMenu in other jsf pages which is not in sorted form, I want a solution where in surrounding the selectOneMenu tag with the custom tag will display the contents in sorting order (or can suggest any other way also we can achieve this)
You could create a custom renderer for the
p:selectOneMenucomponent. Create a new class, saymy.custom.MySelectOneMenuRenderer, and extendSelectOneMenuRenderer. In this you want to@OverridetheencodeInputmethod to something like:I've checked this with PrimeFaces 10. If you need the source for a different PrimeFaces version, check the
SelectOneMenuRenderersource code and select the according version tag (note that from PrimeFaces 11 the path changed). Note that the method you need to override, might be different in other versions (not likely, but possible).Add your custom renderer to the
render-kitsection in yourfaces-config.xmllike:Please note that this will sort the options every time for any
p:selectOneMenurender, which comes with a performance penalty.