【问题标题】:Primefaces commandButton not updating datatable. Is update attribute requiredPrimefaces commandButton 不更新数据表。是否需要更新属性
【发布时间】:2014-07-03 18:16:56
【问题描述】:

我在搜索页面上将 <h:commandButton> 标记更改为 PrimeFaces <p:commandButton> 标记,我的数据表停止显示结果。添加update 属性后,事情再次起作用。我只是想了解是我如何实现整体功能(viewscope、action vs actionListener 等)还是真的需要 update 属性?

<h:form id="search_form">
    <p:inputText id="search" value="#{searchBean.searchString}" />
    <p:commandButton update="search_form" value="Search" action="#{searchBean.searchByString}" >
    </p:commandButton>

<p:dataTable id="output" var="res" value="#{searchBean.results}" emptyMessage="No results found with given criteria">

etc...
@ViewScoped
@ManagedBean
public class SearchBean {

@Inject
private SearchRepository searchRepository;
private List<Results> res;
private String searchString; 

public SearchBean() {
        }

public String searchByString()
{
    this.setRes(searchRepository.searchBySingleString(searchString));
}

【问题讨论】:

  • update 属性是客户端 (UA) 可见更改所必需的。

标签: jsf primefaces


【解决方案1】:

h:commandButton 和p:commandButton 之间的一个区别是第二个默认执行 ajax 请求,而第一个执行普通 POST 请求。

在 ajax 请求中,您必须指定发送表单时要处理的内容以及响应发生时要更新的内容。 p:commandButton 默认不更新任何内容,这就是您的表格未正确填充的原因。

另请参阅:

【讨论】:

    猜你喜欢
    • 2016-01-16
    • 2014-12-10
    • 2015-03-26
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多