【问题标题】:How to dynamically add jsf component using ajax [duplicate]如何使用ajax动态添加jsf组件[重复]
【发布时间】:2017-02-10 07:07:58
【问题描述】:

目前我有这段代码,它通过 html 请求动态添加组件。它按我的预期工作。但我想通过使用 ajax 请求而不是 html 添加组件。

test.xhtml

    <h:dataTable value="#{testController.items}" var="item">
        <h:column><h:inputText value="#{item.name}" /></h:column>
        <h:column><h:commandButton value="remove" action="#{testController.remove(item)}" /></h:column>
    </h:dataTable>
    <h:commandButton value="add" action="#{testController.add}" />

支持豆

@ManagedBean
@ViewScoped
public class TestController implements Serializable {

    private List<Language> items = new ArrayList<Language>();

    public void add() {
        items.add(new Language());
    }

    public void remove(Language item) {
        items.remove(item);
    }

    public List<Language> getItems() {
        return items;
    }
}

现在我需要使用 ajax 请求来执行此操作。我该怎么做?

【问题讨论】:

    标签: ajax jsf jsf-2


    【解决方案1】:

    这段代码对我有用

    <h:dataTable id="testTable" value="#{testController.items}" var="item">
            <h:column><h:inputText value="#{item.name}" /></h:column>
            <h:column><h:commandButton value="remove" action="#{testController.remove(item)}" /></h:column>
        </h:dataTable>
                <h:commandButton value="add" action="#{testController.add}">
                    <f:ajax execute="@this" render="testTable" />
                </h:commandButton>
    

    【讨论】:

      猜你喜欢
      • 2016-08-27
      • 2012-11-21
      • 1970-01-01
      • 2011-08-29
      • 2011-09-07
      • 2012-12-02
      相关资源
      最近更新 更多