在p:forEach循环中使用p:commandLink将参数传递给actionListener方法

时间:2013-11-28 10:01:00

标签: jsf primefaces parameters facelets graphicimage

我有一个对话框,其中包含命令链接中的图形图像列表。单击命令链接时,我想将图像名称作为动作侦听器方法参数传递。

Dialog的代码:

<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>

调用动作侦听器方法,但是我没有收到参数imageName。它是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);
    }

}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

<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>

非常感谢帮助我的每个人(@BalusC)。