【问题标题】:page does not refresh after an action is called调用操作后页面不刷新
【发布时间】:2011-04-23 11:45:25
【问题描述】:

我有一个commandLink 和一个actionListener,它调用一个方法来更改text 的值。同样的commandLink 有一个action 会重新加载页面。当我单击commandLink 时,会调用actionListener。但是 action 只有在我刷新浏览器时才完成——显示文本的更新值。为什么outputText 没有自动更新?

一些代码: home.jspx

(...)
<f:view>
 <table id="main_table">
 <tr><td width="160px"><jsp:directive.include file="./logo.jspx" /></td>
      <td><jsp:directive.include file="./header.jspx" /></td></tr>
 <tr><td width="160px"><jsp:directive.include file="./vertical_navigation.jspx" /></td>
      <td align="center"><ice:outputText value="main" /></ice:outputText></td></tr>
 </table>
</f:view>
(...)

customer.jspx 相同,但outputText 的值为#{customer.text} vertical_navigation.jspx:许多命令链接,如下所示:

(...) 
<ice:form id="nav_form"><ice:panelGrid columns="1">
    <ice:panelCollapsible expanded="true">
    <f:facet name="header"><ice:panelGroup>
      <ice:outputText value="Customer" />
     </ice:panelGroup></f:facet>
     <ice:panelGrid columns="1">
      <ice:commandLink actionListener="#{client.defineText}" 
      immediate="true" action="customer" id="list">
       <ice:outputText value="List" />
      </ice:commandLink>
(...)

豆子:

(...)
public String text;
public void defineText(ActionEvent evt) { 
 text = ... some text related to the link
}
public String getText() {
 return text;
}

嗯,一切正常,除了我必须在单击链接时刷新页面,以便更新 text 的值。我在 bean 方法中放入了一些 System.out.println() satatements,并注意到每当我单击链接时都会调用 defineText 方法。但是 getText 仅在刷新后才被调用。输出是这样的:

// click the link "list"
called defineText for link list
// click the link "new"
called defineText for link new
// click the link "external"
called defineText for link external
// refresh the broswer
called getText // this will show the updated value of "text" for the link "external"
// click the link "new"
// refresh the broswer
called defineText for link new
called getText // this will show the updated value of "text" for the link "new"

我正在使用 JSF 1.2IceFaces 1.8.2

【问题讨论】:

    标签: java web-applications jsf icefaces


    【解决方案1】:

    它是关于循环和事件的处理方式。

    根据我的经验,有两种解决方法:

    1) 将事件排队(检查不同类型的事件)直到更新值。

    2) 通过使用另一个标签来解决问题

    【讨论】:

      【解决方案2】:

      我终于找到了解决办法。我删除了 JSF 1.2 Apache Myfaces 并替换为 Sun RI jars。如果有人能解释它为什么起作用,我将不胜感激。

      【讨论】:

        【解决方案3】:

        我不使用 IceFaces,但尝试从您的命令链接中删除 immediate="true" - 使用标准 h:commandLink 可能会导致问题。

        【讨论】:

        • 我以前试过。调用了 getText 方法(页面已刷新,很好),但不再调用 defineText 方法,这意味着 actionListener 不起作用——不好。 :-(
        猜你喜欢
        • 2021-10-08
        • 1970-01-01
        • 2015-11-14
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        • 1970-01-01
        • 1970-01-01
        • 2012-04-12
        相关资源
        最近更新 更多