Jopse
Jopse

Reputation: 89

Primefaces: contextMenu doesn't throw a Dialog

I want an itemMenu from a contextMenu to launch a Dialog. But when I click in the itemMenu the Dialog doesn't appear. I have this contextMenu:

<p:contextMenu for="processes">
    <p:menuitem  styleClass="homeIE" update="form" value="Start Process"   icon="ui-icon-play"     actionListener="PF('startDialog').show;" rendered="#{homeBean.selectedLogicalServer.os eq 'Windows'}"/>
    <p:menuitem  styleClass="homeIE" update="form" value="Stop Process"    icon="ui-icon-stop"     actionListener="PF('stopDialog').show;"/>
    <p:menuitem  styleClass="homeIE" update="form" value="Restart Process" icon="ui-icon-seek-end" actionListener="PF('restartDialog').show;" rendered="#{homeBean.selectedLogicalServer.os eq 'Windows'}"/>
</p:contextMenu>

I have this dataTable:

<p:dataTable id="processes" var="process" value="#{homeBean.processesList}" filteredValue="#{homeBean.filteredProcesses}"
             rowKey="#{process.pid}" selection="#{homeBean.selectedProcesses}" 
             paginator="true" rows="15" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
             rowsPerPageTemplate="15,20,25,30" selectionMode="single">
    <f:facet name="header">
        <h:outputText value="Processes" />
    </f:facet>
    <p:column name="owner" filterBy="#{process.owner}" filterMatchMode="contains" sortBy="owner" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'DESCRIPTION' : 'OWNER'}">
        <h:outputText value="#{process.owner}" />
    </p:column>
    <p:column name="pid" filterBy="#{process.pid}" filterMatchMode="exact" sortBy="pid" headerText="PID">
        <h:outputText value="#{process.pid}" />
    </p:column>
    <p:column name="ppid" filterBy="#{process.ppid}" filterMatchMode="exact" sortBy="ppid" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'TYPE' : 'PPID'}">
        <h:outputText value="#{process.ppid}" />
    </p:column>
    <p:column name="c" filterBy="#{process.c}" filterMatchMode="exact" sortBy="c" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'STATE' : 'C'}">
        <h:outputText value="#{process.c}" />                                                
    </p:column>
    <p:column name="stime" filterBy="#{process.stime}" filterMatchMode="contains" sortBy="stime" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'WIN32 EXIT CODE' : 'STIME'}" rendered="#{homeBean.selectedLogicalServer.os eq 'Windows'}">
        <h:outputText value="#{process.stime}" />
    </p:column>
    <p:column name="tty" filterBy="#{process.tty}" filterMatchMode="contains" sortBy="tty" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'SERVICE EXIT CODE' : 'TTY'}" rendered="#{homeBean.selectedLogicalServer.os eq 'Windows'}">
        <h:outputText value="#{process.tty}" />
    </p:column>
    <p:column name="time" filterBy="#{process.time}" filterMatchMode="contains" sortBy="time" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'CONTROL POINT' : 'TIME'}" rendered="#{homeBean.selectedLogicalServer.os eq 'Windows'}">
        <h:outputText value="#{process.time}" />
    </p:column>
    <p:column name="cmd" filterBy="#{process.cmd}" filterMatchMode="contains" sortBy="cmd" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'NAME' : 'CMD'}">
        <h:outputText value="#{process.cmd}" />
    </p:column>
</p:dataTable>

And I have these dialogs:

<p:dialog header="Start Process" widgetVar="startDialog" minHeight="40" styleClass="dialogPosition">
    <h:outputText    value="You are going to start the process, Are you sure?"/>
</p:dialog>
<p:dialog header="Stop Process" widgetVar="stopDialog" minHeight="40" styleClass="dialogPosition">
    <h:outputText    value="You are going to stop the process, Are you sure?"/>
</p:dialog>
<p:dialog header="Restart Process" widgetVar="restartDialog" minHeight="40" styleClass="dialogPosition">
    <h:outputText    value="You are going to restart the process, Are you sure?"/>
</p:dialog>

All the code is inside this tag:

<h:form id="form" onkeypress="return event.keyCode != 13">
    <p:contextMenu for="process">
    ...
    </p:contextMenu>
    <p:dataTable id="processes">
    ...
    </p:dataTable>
    <dialog>
    ...
    </dialog>
    <dialog>
    ...
    </dialog>
    <dialog>
    ...
    </dialog>
</h:form>

In the log:

Grave: javax.el.ELException: Cannot convert LogicalServerProcess [owner=root, pid=11500, ppid=11499, c=0, stime=11:27, tty=pts/1, time=00:00:00, cmd=ps -ef ] desde tipo class corp.gs.produban.atf.ccs.bean.LogicalServerProcess to interface java.util.List

Upvotes: 1

Views: 496

Answers (1)

stg
stg

Reputation: 2797

The actionListener is supposed to invoke some action method on the server side. The part PF('startDialog').show; is just some JavaScript to show the dialog on the client side

You just have to use onclick (or one of the others JavaScript event handlers starting with on...) instead of actionListener here.

Beside that there is another problem in your code, but one cannot exactly say what it is, as the essential parts of code of your Bean are missing. I assume selectedProcesses in your bean is of type List<LogicalServerProcess> but you have chosen selection mode single, so it has to be of type LogicalServerProcess instead.

Upvotes: 3

Related Questions