2012-02-07 45 views
0

我想在创建新元素时动态刷新。 我来到了3个解决方案,并且想知道哪个最好,哪个更喜欢。或者说:我喜欢nr。 3(阿贾克斯)最多,但不幸的是,这是一个不工作。我想知道如何让它工作。 a)。添加新条目后用ajax刷新数据表

a)。与@Observes:

公共类门面{

private List<Customer> customerList; 

public void createNew() { 
    service.create(newCustomer); 
    event.fire(newCustomer); 
} 

public void onCustomerChanged(
     @Observes(notifyObserver = Reception.IF_EXISTS) final Customer newCustomer) { 
    findAll(); 
} 

@PostConstruct 
public void findAll() { 
    customerList = service.findByNamedQuery("Customer.ALL"); 
} 

public List<Customer> getCustomerList() { 
    return customerList; 
} 

}

b)中。只需在createNew的dontect中直接调用findAll更新方法:

public void createNew() { 
     service.create(newCustomer); 
     findAll(); 
    } 

c)。使用Ajax:

public void createNew() { 
     service.create(newCustomer); 
    } 


    <h:form> 
     <h:commandButton id="register" action="#{facade.createNew()}" 
      value="Register"> 
      <f:ajax execute="@form" render=":customerTable" /> 
      </h:commandBUtton> 
    </h:form> 

<h:datatable id="customerTable" var="_customer" value="facade.customerList"> 

可惜的是阿贾克斯的东西不工作延迟:例如,创建customer1表>什么也没有发生。创建cust2>数据表刷新并显示cust1。等等。

我该如何解决这个问题?

非常感谢

回答

0

您需要添加新条目后重新加载列表中,完全按照你在B均无)。