JSF中的commandButton问题 [英] commandButton issue in JSF

查看:168
本文介绍了JSF中的commandButton问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于我的要求的简短介绍.

Brief intro about my requirement.

我有一个空的JSF dataTable.
现在,当我单击一个按钮时,它应该用数据填充空的数据表.

I have an empty JSF dataTable.
Now, when I click on a button, it should fill the empty datatable with data.

<h:commandButton value="Search" action="#{myBean.searchresults}" />

问题:
当我单击该按钮时,它会将数据填充到dataTable中,但是当我第一次加载应用程序时(刷新页面)会立即向我显示相同的页面.
我希望页面不刷新本身,并显示填充的数据.

Problem:
When I click on the button, it populates the data to the dataTable but instantly shows me the same page when I load my application first time (refresh the page).
I want the page to not refresh itself and show the populated data.

最近2天,我一直在此问题上停留.
请提供您的建议.

I am stuck in this issue for the last 2 days.
Kindly provide your advice.

提前谢谢!

谢谢, 李

推荐答案

因此,您需要异步提交和部分渲染吗? <f:ajax> 标记适用于此. 您可以在execute属性中指定提交上下文,并在render属性中指定要更新的客户端ID.

So you want an asynchronous submit and a partial render? There the <f:ajax> tag is for. You can specify the submit context in execute attribute and the to-be-updated client IDs in render attribute.

例如

<h:form>
    <h:inputText value="#{bean.query}" />
    <h:commandButton value="Search" action="#{bean.search}">
        <f:ajax execute="@form" render=":results" />
    </h:commandButton>
</h:form>
<h:panelGroup id="results">
    <h:dataTable value="#{bean.results}" rendered="#{not empty bean.results}">
        ...
    </h:dataTable>
</h:panelGroup>

使用

public void search() {
    results = service.find(query);
}

这篇关于JSF中的commandButton问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆