如何add/remove行(inputText,ouputText)JSF?

How to add/remove row (inputText ,ouputText) JSF?

我有这个:

<p:outputLabel for="author" value="Author " rendered="#{documentController.show}"/>

<p:selectOneMenu id="author"
                 value="#{documentController.author}"
                 rendered="#{documentController.show}"
                 effect="fade"
                 editable="true"
                 filter="true"
                 filterMatchMode="startsWith">

    <f:selectItem itemLabel="Select One" itemValue="" />
    <f:selectItems value="#{authorController.itemsAvailableSelectOne}" />
</p:selectOneMenu>

我想要这样的行为:如果我单击作者字段旁边的添加图标,然后为我的第二作者创建另一个 'outputText, SelectOneMenu , add link, remove link',如果我单击另一个添加图标,然后创建第三作者和等等。

删除图标也是如此。

你可以这样走。

<h:form id="form1">
    <h:panelGroup id="panel1">
        <ui:repeat value="#{documentController.author}" var="auth">

            <p:outputLabel for="author"
                           value="Author "
                           rendered="#{documentController.show}"/>

            <p:selectOneMenu id="author"
                             value="#{auth}"
                             rendered="#{documentController.show}"
                             effect="fade"
                             editable="true"
                             filter="true"
                             filterMatchMode="startsWith">

                <f:selectItem itemLabel="Select One" itemValue="" />
                <f:selectItems value="#{authorController.itemsAvailableSelectOne}" />
            </p:selectOneMenu>

            <h:commandLink value="Add">
                <f:ajax execute="@form"
                        render=":form1:panel1"
                        listener="#{documentController.addAuthor}" />
            </h:commandLink>
        </ui:repeat>
    </h:panelGroup>
</h:form>

在支持 bean 上你可以做这样的事情。

List<String> author = new ArrayList<String>();
String s1 = "";
author.add (s1);

public void addAuthor(AjaxBehaviorEvent ajaxEvent) {
    String s = ""
    author.add(s);
}