【问题标题】:commandButton issue in JSFJSF 中的命令按钮问题
【发布时间】:2012-03-21 11:42:49
【问题描述】:

简要介绍我的要求。

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

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

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

过去 2 天我一直在这个问题上。
请提供您的建议。

提前致谢!

谢谢, 李

【问题讨论】:

  • 你能发布一些相关的代码吗?谢谢!
  • 请出示一些代码!我最好的选择是您的 @ManagedBean 范围错误或一些混乱的 AJAX 更新。干杯!
  • 请找代码sn-p:
  • 请显示您的 ManagedBean 代码(并确保其可见)!干杯

标签: jsf-2


【解决方案1】:

所以您想要异步提交和部分渲染? &lt;f:ajax&gt; 标签用于。 您可以在execute 属性中指定提交上下文,在render 属性中指定要更新的客户端ID。

例如

<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);
}

【讨论】:

    【解决方案2】:

    searchresults 返回了一些导航逻辑吗?

    如果没有,

    使searchresults成为一个void方法

    public void searchresults(){
    //logic here
    }
    

    并将 f:ajax 添加到按钮

    <h:commandButton value="Search" action="#{myBean.searchresults}" >
        <f:ajax execute="@form" render="@form"/>
    </h:commandButton>
    

    【讨论】:

    • 感谢丹尼尔的回复,现在我的问题已经解决了... :)
    猜你喜欢
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 2015-01-09
    • 2017-10-04
    • 2015-02-24
    • 2010-10-13
    • 1970-01-01
    相关资源
    最近更新 更多