【问题标题】:<h:commandButton> is not refreshing page after actioned<h:commandButton> 操作后不刷新页面
【发布时间】:2013-03-13 22:58:30
【问题描述】:

您好,我们与 a4j 标签一起使用。

在这里,我们在单击按钮后从数据库中检索数据。即使数据在服务器中可用,它也不会显示在视图中。手动刷新网页后会导致数据显示。

这里是代码 sn-p ....这里有一些代码

  <rich:tab id="menu5" label="Recall">
  <ui:include src="/pages/mctrans/reCallMcifTrans.xhtml" />  
  </rich:tab>

reCallMcifTrans.xhtml 包含以下代码

<h:commandButton type="button" id="reCallbutton1" value="   Search   "
    styleClass="commandExButton">
    <a4j:support event="onclick" id="ajsf12"
        oncomplete="javascript:alert('Search   Completed');javascript:document.body.style.cursor='default';"
        action="#{mcifRecallTransBean.reCallSearch}" reRender="reCallgrid1" />
</h:commandButton>

【问题讨论】:

  • 你的bean的作用域是什么? url中有get参数吗?
  • Bean 范围是会话级别。传递搜索参数

标签: jsf richfaces


【解决方案1】:

您似乎正在使用 RichFaces 3.3。因此,您不需要&lt;h:commandButton&lt;a4j:support&gt;,因为您可以使用已经这样做的&lt;a4j:commandButton&gt;。您可以将代码重构为:

<a4j:commandButton type="button" id="reCallbutton1" value="Search"
    styleClass="commandExButton"
    action="#{mcifRecallTransBean.reCallSearch}"
    reRender="reCallgrid1"
    oncomplete="javascript:alert('Search   Completed');javascript:document.body.style.cursor='default';" />

确保您的reCallgrid1 组件在&lt;a4j:commandButton&gt; 的同一&lt;h:form&gt; 中可用。

由于您还希望在单击按钮时添加搜索数据时等待 行为,因此您可以使用&lt;a4j:status&gt;&lt;a4j:commandButton&gt;,如&lt;a4j:status&gt; demo 所示。这是一个基本示例:

<a4j:commandButton type="button" id="reCallbutton1" value="Search"
    styleClass="commandExButton"
    action="#{mcifRecallTransBean.reCallSearch}"
    reRender="reCallgrid1" />
<!-- Note that there's no oncomplete in this case -->
<a4j:status for="reCallbutton1">
    <f:facet name="start">
        <h:graphicImage  value="/res/images/wait.gif"/>
    </f:facet>
</a4j:status>

最后但同样重要的是,您应该将托管 bean 切换到请求范围并使用强大的 RichFaces &lt;a4j:keepAlive&gt; 来模拟 JSF 2 @ViewScoped。您甚至可以在托管 bean 上以注释的形式使用它(无需额外配置):

@KeepAlive
public class McifRecallTransBean {
    //managed bean code here...
}

【讨论】:

    【解决方案2】:

    当您在 bean 中使用请求参数时,您需要通过您的操作再次传递它们:

    <h:commandButton type="button" id="reCallbutton1" value="Search" styleClass="commandExButton">
        <a4j:support event="onclick" id="ajsf12" oncomplete="javascript:alert('Search  Completed');javascript:document.body.style.cursor='default';" action="#{mcifRecallTransBean.reCallSearch}" reRender="reCallgrid1" />
        <f:param name="param1" value="#{param['param1']}" />
        <f:param name="param2" value="#{param['param2']}" />
    </h:commandButton>
    

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 2021-10-08
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多