Search code examples
primefacesjsf-2

How to pass arguments to modal window from within data table in Prime Faces 6.2?


I need to have a link showing a modal window when pushed near a row value in a data table as shown down here but apparently my way to pass a value right from the data table via request parameters to the modal window is wrong. So I receive blank area inside window. Here the picture of how it looks and a code sample (yellow triangle is a link): enter image description here

<p:dataTable id="ticketList" value="#{tickets}" var="ticket">

        <p:column headerText="Статус экспорта">
            <h:outputText value="#{ticket.exportStatus.caption}"/>
            <p:commandLink id="ticketErrorShowlink"
                           action="ticketError"
                           oncomplete="PF('exportError').show();">
                <h:graphicImage url="/images/shim.gif" style="border:0; vertical-align:center" width="5"/>
                <h:graphicImage id="headImageHelp" url="/images/mess_warning.gif" title="Ошибки экспорта"
                                style="border:0; vertical-align:bottom"/>
                <f:param name="errorText" value="#{ticket.errors}"/>
            </p:commandLink>
        </p:column>
</p:dataTable>

<p:dialog id="ticketErrorModalPanel" header="Ошибки экспорта" widgetVar="exportError">
        <f:facet name="controls">
            <h:outputLink id="phidelink" value="#hide" onclick="PF('exportError').hide();">
                <h:graphicImage value="/images/close.png" style="border:0; cursor:pointer;"/>
            </h:outputLink>
        </f:facet>

        <p:panelGrid columns="1" columnsWidth="540px">
            <h:outputText value="#{requestParameters.errorText}" escape="false" />
        </p:panelGrid>
        <p:commandLink id="closeLink" oncomplete="PF('exportError').hide();" value="Закрыть" />
</p:dialog>

So, is there any rules to follow either passing parameters from data table or when receiving them in a tag to resolve such problem? Thanks for your answers in advance. Any additional info will be added if there's a need.


Solution

  • Resolved: added <p:ajax> that sets value from the data table to a backing bean.

    <h:form id="protocolForm">
      <p:dataTable id="ticketList" value="#{tickets}" var="ticket">
        <p:column headerText="Статус экспорта">
          <h:outputText value="#{ticket.exportStatus.caption}"/>
          <p:commandLink id="ticketErrorShowlink"
                         oncomplete="PF('exportError').show()">
    
             <h:graphicImage url="/images/shim.gif" style="border:0; vertical-align:center" width="5"/>
             <h:graphicImage id="headImageHelp" url="/images/mess_warning.gif" title="Ошибки экспорта"
                             style="border:0; vertical-align:bottom"/>
             <p:ajax listener="#{protocolForm.setErrors(ticket.errors)}" update=":protocolForm:ticketErrorPanelGroup"/>
          </p:commandLink>
       </p:column>
    </p:dataTable>
    
    // dialog down there
    

    Put a modal window to the <h:panelGroup>:

    // data table
      <h:panelGroup id="ticketErrorPanelGroup">
        <p:dialog id="ticketErrorModalPanel" header="Ошибки экспорта" widgetVar="exportError">
            <f:facet name="controls">
                <h:outputLink id="phidelink" value="#hide" onclick="PF('exportError').hide();">
                    <h:graphicImage value="/images/close.png" style="border:0; cursor:pointer;"/>
                </h:outputLink>
            </f:facet>
    
            <p:panelGrid columns="1" columnsWidth="540px">
                <h:outputText value="#{protocolForm.getErrors()}" escape="false" />
            </p:panelGrid>
            <p:commandLink id="closeLink" oncomplete="PF('exportError').hide()" value="Закрыть" />
        </p:dialog>
      </h:panelGroup>
    </h:form>
    

    Also, there's a backing bean - ProtocolForm to get/set values (it's created by Spring Web Flow so there isn't the @MenagedBean annotation).

    public class ProtocolForm { 
       private String errors;
    
       // getter/setter
    }
    

    After setting query complete the window opens getting the value.