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

Forum rules
Please note that response time for technical support is within 3-5 business days.
Post Reply
alex086
Posts: 4
Joined: 28 Mar 2018, 16:33

03 Jun 2020, 13:43

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

alex086
Posts: 4
Joined: 28 Mar 2018, 16:33

10 Jun 2020, 12:01

Can anyone reproduce this problem or is it just me?

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

16 Jun 2020, 11:52

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,

alex086
Posts: 4
Joined: 28 Mar 2018, 16:33

16 Jun 2020, 12:06

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!

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

17 Jun 2020, 09:50

Yes ;)

Best Regard,

Post Reply

Return to “Serenity - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests