Page 1 of 1

p:selectOneMenu in md-inputfield : first option not appearing

Posted: 03 Jun 2020, 13:43
by alex086
Hi,

I'm using Serenity 2.0.1 and Primefaces 7.0 and I've been enjoying them thoroughly in my project for the past 6 months. However, I've had some issues with p:selectonemenu...

The following code works great:

Code: Select all

<div class="ui-g">
	<h:form>
		<div class="ui-g-12">
			<p:selectOneMenu value="#{MyBean.selectedItem}" converter="ItemConverter">
    				<f:selectItem noSelectionOption="true" itemLabel="Select an item"/>
   				<f:selectItems value="#{MyBean.itemList}" var="item" itemLabel="#{item.label}" itemValue="#{item}" />
	    		</p:selectOneMenu>
		</div>
	</h:form>
</div>
The following has an issue:

Code: Select all

<div class="ui-g">
	<h:form>
		<div class="ui-g-12">
			<h:panelgroup styleclass="md-inputfield">
				<p:selectOneMenu value="#{MyBean.selectedItem}" converter="ItemConverter">
    					<f:selectItem noSelectionOption="true" itemLabel="Select an item"/>
   					<f:selectItems value="#{MyBean.itemList}" var="item" itemLabel="#{item.label}" itemValue="#{item}" />
	    			</p:selectOneMenu>
	    		</h:panelgroup>
		</div>
	</h:form>
</div>
In the second code, the "Select an item" option does not appear in the option list. In fact, if I remove that option altogether, then the first item of MyBean.itemList doesn't appear. It can be pre-selected though, thus appearing as the selected option, but it isn't available in the option list.
This is true both inside and outside a p:dialog, so it isn't related to the similar post: viewtopic.php?f=73&t=57847.

My workaround is to have an extra f:selectItem that is sacrificed to the Primefaces gods, appeasing their wrath and sparing the selectitems I need to render.

Is this a common issue or is my environment somehow jinxed?

Cheers

Re: p:selectOneMenu in md-inputfield : first option not appearing

Posted: 10 Jun 2020, 12:01
by alex086
Can anyone reproduce this problem or is it just me?

Re: p:selectOneMenu in md-inputfield : first option not appearing

Posted: 16 Jun 2020, 11:52
by aragorn
Hi,

Please try;

Code: Select all

<div class="ui-g">
	<h:form>
		<div class="ui-g-12">
			<h:panelgroup styleclass="md-inputfield">
				<p:selectOneMenu value="#{MyBean.selectedItem}" converter="ItemConverter">
    					<f:selectItem noSelectionOption="true" itemLabel=""/>
   					<f:selectItems value="#{MyBean.itemList}" var="item" itemLabel="#{item.label}" itemValue="#{item}" />
	    			</p:selectOneMenu>
	    			<label>Select an item</label>
	    		</h:panelgroup>
		</div>
	</h:form>
</div>
For the animation to work correctly, the onemenu's first element must have an empty label. And please add a label tag.

Best Regards,

Re: p:selectOneMenu in md-inputfield : first option not appearing

Posted: 16 Jun 2020, 12:06
by alex086
So if I understand properly, there must always be an empty item before all the other options?
And yeah, I forgot the label in my example.

Thanks a lot!

Re: p:selectOneMenu in md-inputfield : first option not appearing

Posted: 17 Jun 2020, 09:50
by aragorn
Yes ;)

Best Regard,