Passing argument to actionListener method with p:commandLink inside c:forEach loop

喜你入骨 提交于 2019-12-25 08:33:04

问题


I have a dialog that contains a list of graphic images inside command links. When a command link is clicked, I want to pass the image name as action listener method argument.

Dialog's code:

<p:dialog id="idSchemaDlg5" widgetVar="schemaDlg" styleClass="maxSizeDialog" position="90,250" style="max-width:1000px;max-height: 1000px;" header="Schéma des circuits">

        <c:forEach id="schemaDataGrid" items="#{historyGenerationBean.schemaList}" var="fileCircuits" varStatus="schemaNum">
            <h:panelGrid   columns="1">
                <h:outputText value="SiteG2R #{historyGenerationBean.g2rNames.get(schemaNum.index)}" style="font-family: Tahoma, Geneva, sans-serif;color: #ED7905;font-size: 16px;font-weight: bold;"/>
                <c:forEach  items="#{fileCircuits}" var="pictureNamesList">
                    <h:panelGrid   columns="#{pictureNamesList.size()}">
                        <c:forEach  items="#{pictureNamesList}" var="imageName">
                            <h:form>
                                <h:panelGroup   style="width:6px">

                                    <p:commandLink actionListener="#{historyGenerationBean.fetchMlpppInformation(imageName)}" >

                                        <p:graphicImage  value="#{imageStreamer.image}"  >
                                            <f:param name="imgName" value="#{imageName}" />
                                        </p:graphicImage>
                                    </p:commandLink>
                                    <h:outputText   value="#{imageName}"  style="width:50%; font-family: Tahoma, Geneva, sans-serif; font-size:70%;color:black;background-color:transparent;text-align:left;"/>


                                </h:panelGroup>
                            </h:form>
                        </c:forEach>
                    </h:panelGrid>

                </c:forEach>
            </h:panelGrid>

        </c:forEach>

    </p:dialog>

The action listener method is invoked, however I don't receive the argument imageName. It is null.

@ManagedBean(name = "historyGenerationBean")
@RequestScoped
public class HistoryGenerationBean implements Serializable {

    @PostConstruct
    public void init() {
        String[] listRegion = new String[6];
        circuitMlpppMap = new HashMap<>();
        listRegion[0] = "Centre-Est";

        regionOptions = createFilterOptions(genBean.getListRegion());


        if (loginBean.connectedUserHasRole("ADMIN")) {
            histories = generationHistoryFacade.findAll();
        } else {
            histories = loginBean.getConnectedUser().getGenerationHistoryList();
        }

        history = new GenerationHistory();
    }


    public void fetchMlpppInformation(String imgName) {
        System.out.println("l'image sélectionnée est: " + imgName);
    }

}

How can I fix this?


回答1:


I was found the solution with .

<p:dialog id="idSchemaDlg5" widgetVar="schemaDlg" styleClass="maxSizeDialog" position="90,250"  style="max-width:1000px;max-height: 1000px;"  header="Schéma des circuits">
            <h:form id="schemaFormId"  dir="#{login.dir}">
                <ui:repeat value="#{historyGenerationBean.schemaList}" var="fileCircuits" varStatus="schemaNum">
                    <ui:repeat value="#{fileCircuits}" var="pictureNamesList">
                        <table>
                            <tbody>
                                <tr>
                                    <ui:repeat value="#{pictureNamesList}" var="imageName">
                                        <td>
                                            <h:panelGrid  columns="1">
                                                <p:commandLink action="#{historyGenerationBean.fetchMlpppInformation}" update=":schemaFormId"   >
                                                    <p:graphicImage  value="#{imageStreamer.image}">
                                                        <f:param name="imgName" value="#{imageName}" />
                                                    </p:graphicImage>
                                                    <f:param name="imgName2" value="#{imageName}" />
                                                </p:commandLink>
                                                <h:outputText   value="#{imageName}"  style="width:50%; font-family: Tahoma, Geneva, sans-serif; font-size:70%;color:black;background-color:transparent;text-align:left;"/>
                                            </h:panelGrid>
                                        </td>
                                    </ui:repeat>
                                </tr>
                            </tbody>
                        </table>

                    </ui:repeat>
           </h:form>
</p:dialog>

Many thanks to everyone who helped me(@BalusC too).



来源:https://stackoverflow.com/questions/20262945/passing-argument-to-actionlistener-method-with-pcommandlink-inside-cforeach-lo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!