简体   繁体   中英

commandLink within PickList in Primefaces passes null value to the managed bean

I am using Primefaces 5.0 and on one of my pages I have this picklist:

<h:form>
...
<p:pickList id="aspectPickList" styleClass="camsPickList" value="#{userAccountMB.aspects}" var="aspect" itemValue="#{aspect}"
    itemLabel="#{aspect.aspectName}" showSourceFilter="true" showTargetFilter="true" converter="appAspectConverter">

    <f:facet name="targetCaption">#{msg['createUser.userAspects.assignedAspects']}</f:facet>
    <f:facet name="sourceCaption">#{msg['createUser.userAspects.availableAspects']}</f:facet>

    <p:column>
        <h:outputText id="aspectName" value="#{aspect.aspectName}" />
        <p:tooltip id="toolTipAspectDescription" for="aspectName" value="#{aspect.description}" />
    </p:column>
    <p:column style="width:30px;">
    #{aspect}
    <p:commandLink process="@this" oncomplete="PF('aspectDetailsDialog').show();" actionListener="#{userAccountMB.setSelectedAspect(aspect)}">
            <p:graphicImage value="#{resource['images:questionmark_icon.jpg']}" />
        </p:commandLink>
    </p:column>

</p:pickList>
...
</h:form>

Managed bean setSelectedAspect method looks like this:

public void setSelectedAspect(AppAspect selectedAspect) {
    this.selectedAspect = selectedAspect;
}

The Scope of the Managed Bean is view.

When I click on the command link with icon, the setSelectedAspect method is invoked, but the selectedAspect parameter is null.

What I need to achieve is to show AspectDetails dialog after clicking the commandLink. The AspectDetails dialog contains details about the previously selected aspect.

if I update the code this way:

<p:column style="width:30px;">
#{aspect}
<p:commandLink process="@this" oncomplete="PF('aspectDetailsDialog').show();" actionListener="#{userAccountMB.selectAspect(aspect)}">
    <p:graphicImage value="#{resource['images:questionmark_icon.jpg']}" />
</p:commandLink>
</p:column>

the #{aspect} directive correctly displays the object signature: com.xyz.app.domain.AppAspect@69e1f7aa.

What am I doing wrong? Do I miss something?

I had the same error, try this:

<p:pickList ...>
    <p:ajax event="select" listener="#{userAccountMB.selectAspectEvent}">
        <f:attribute name="aspectParam" value="#{aspect}" />
    </p:ajax>

    <f:facet ...>
    <f:facet ...>

    <p:column>...</p:column>

    <p:column style="width:30px;">
        <p:commandLink process="@this" oncomplete="PF('aspectDetailsDialog').show();">
            <p:graphicImage value="#{resource['images:questionmark_icon.jpg']}" />
        </p:commandLink>
    </p:column>
</p:pickList>

And the controller:

public void selectAspectEvent(SelectEvent event) {
    AppAspect aspectParam = (AppAspect) event.getObject();
    if(aspectParam!=null){
        this.selectedAspect = aspectParam;
    }
}

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM