1
votes

I am using JSF and PrimeFaces. While trying to use PrimeFaces component p:selectOneMenu I found some issue.

<h:form>
    <p:panel header="Select an offer and the date for the report" style="margin-bottom: 10px">
        <h:panelGrid columns="2" cellpadding="5px">
            <p:outputLabel for="offer" value="Offer: "/>
            <p:selectOneMenu id="offer" value="#{partnerSales.selectedOffer}" style="width: 200px;">
                <p:ajax event="change" update="year" listener="#{partnerSales.onOfferChange}"/>
                <f:selectItem itemLabel="Select an offer: " noSelectionOption="true" itemValue=""/>
                <f:selectItems value="#{partnerSales.allOffers}"/>
            </p:selectOneMenu>

            <p:outputLabel for="year" value="Year: "/>
            <p:selectOneMenu id="year" value="#{partnerSales.selectedYear}" style="width: 200px">
                <p:ajax update="month"/>
                <f:selectItem itemLabel="Select a year: " itemValue="" noSelectionOption="true"/>
                <f:selectItems value="#{partnerSales.years}"/>
            </p:selectOneMenu>

            <p:outputLabel for="month" value="Month: "/>
            <p:selectOneMenu id="month" value="#{partnerSales.selectedMonth}" style="width: 200px">
                <f:selectItem itemLabel="Select a month: " itemValue="" noSelectionOption="true"/>
                <f:selectItems value="#{partnerSales.months}"/>
            </p:selectOneMenu> 
        </h:panelGrid>

        <p:separator/>

        <p:commandButton value="Send" actionListener="#{partnerSales.displayData}"/>
    </p:panel>
</h:form>

So, I have a selectOneMenu component which has a several options. By the default first item is "Select an offer: " with a null value and its not used for selection. Moreover, I use listener to catch value changing to update next components. But, when I try to change the values nothing is going. But when I select the first item from dropdown menu listener prints that it was visited. Where is the mistake? I cannot understand such strange behavior)

1
If you want the value to be processed directly you need to add a process="@this" to the ajax events, if not they should be submitted with the commandButton. If you want a submit with the commandButton your code is correct, if you use normal data types as values. But maybe you try to use a SelectOneMenu with custom objects. That wouldn't work, then you need a converter. Can you show us your bean and do you get any error message?lastresort
@lastresort yes, I want to use command button. You are right I use custom object. So, your answer was right I've added converter and that is worked! Thank you very much!catscoolzhyk

1 Answers

0
votes

Thanks to @lastresort! When I used SelectOneMenu component as a value I've added custom object.

To use custom objects in such components you need to add a custom converter.