2016-10-02 23 views
0

現在、私は動的にhtml要求を介してコンポーネントを追加するこのコードを持っています。私は期待どおりに働いています。しかし、htmlの代わりにajaxリクエストを使用してコンポーネントを追加したいと思います。ajaxを使用して動的にjsfコンポーネントを追加する方法

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}" /> 

バッキングBean

@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リクエストを行う必要があります。どうやってやるの?

答えて

0

このコードは私

<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> 
のために働いていました
関連する問題