2017-05-08 97 views
0

我开发了一个视图来保存Child对象。一切工作正常,但看到我在<p:dataTable>我的其他对象,我总是不得不手动重新加载站点。按钮点击后网站不会重新加载

下面的<p:commandButton>的代码将表单数据发送到我的控制器类。

<h:panelGrid columns="3"> 
    <p:commandButton value="Save" 
    action="#{childController.doSaveChild}" 
    oncomplete="PF('childAddDialog').hide()" 
    update=":childForm"/> 
</h:panelGrid> 

我已经试过使用ajax="false",但它不起作用。

如何在点击保存按钮后重新加载站点?

UPDATE:

<p:dataTable>从我view.xhtml:

<h:form id="childForm"> 
<p:dataTable id="childTable" var="child" 
    widgetVar="childTable" value="#{childController.children}" 
    paginator="true" rows="10" paginatorPosition="bottom" 
    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} 
    {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} 
    {Exporters}" 
    rowsPerPageTemplate="10,25,50"> 

<p:column headerText="Firstname"  
    filterBy="#{child.firstName}"  
    sortBy="#{child.firstName}" filterStyle="display:none">  
    <h:outputText value="#{child.firstName}"/>     
</p:column>            
<p:column headerText="Lastname"   
    filterBy="#{child.lastName}"  
    sortBy="#{child.lastName}" 
    filterStyle="display:none">    
    <h:outputText value="#{child.lastName}"/> 
</p:column>            
<p:column headerText="Birthday"  
    filterBy="#{child.birthday}"  
    sortBy="#{child.birthday}" 
    filterStyle="display:none">  
    <h:outputText value="#{child.birthday}"/>    
</p:column> 
</dataTable> 
</form> 

这里为视图提供孩子的方法:

public Collection<Child> getChildren(){ 
    return children; 
} 

@PostConstruct 
public void initList(){ 
    setChildren(childService.getAllChildren()); 
} 
+1

您正试图让您的解决方法正常工作。我会专注于最初的问题。 –

+0

你认为最初的问题是什么?我只想让网站自动重新加载。 – SteveOhio

+1

正确的解决方案将是更新工作。你需要发布你的dataTable xhtml和相关的支持bean代码。 –

回答

1

的XHTML代码从上面的罚款。

为了让站点自动更新,有必要在控制器中的save-method之后再次加载带有所有子项的列表。

public void doSaveChild(){ 
    childService.saveChild(child); 
    child = null; 
    initNewChild(); 
    initList(); //this is needed to get up-to-date list in view 
} 
+0

我建议在命令按钮上使用'process =“@ this”' –

-1

你可以或者通过做javascript:

<p:commandButton value="Save" 
action="#{childController.doSaveChild}" process="@form" update="@none" oncomplete="location.reload();"/> 

或动作方法返回字符串:

public String doSaveChild(){ 
//your logic 
return "/yourpage?faces-redirect=true"} 
相关问题