调用操作后页面不刷新

发布于 2024-09-27 00:32:34 字数 2487 浏览 1 评论 0原文

我有 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>
(...)

bean:

(...)
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() 语句,并注意到每当我单击链接时就会调用 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

I have commandLink with an actionListener that calls a method to change the value of text. The same commandLink has an action that reloads the page. When I click the commandLink, the actionListener is called. But the action only is completed --showing the updated value of text-- when I refresh the browser. Why isn't the outputText being automatically updated?

Some code:
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 is the same, but the value of the outputText is #{customer.text}
vertical_navigation.jspx: many command links like the following:

(...) 
<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>
(...)

the bean:

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

Well, everything works fine, except that I have to refresh the page when I click a link so that the value of text is updated. I put some System.out.println() satatements inside the bean methods and noticed that the defineText method is called whenever I click a link. But the getText is called only after a refresh. The output is like this:

// 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"

I'm working with JSF 1.2 and IceFaces 1.8.2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

━╋う一瞬間旳綻放 2024-10-04 00:32:34

我终于找到了解决方案。我删除了 JSF 1.2 Apache Myfaces 并代之以 Sun RI jar。如果有人能解释为什么它有效,我将不胜感激。

I have finally found a sollution. I removed the JSF 1.2 Apache Myfaces and substituted by the Sun RI jars. If anyone can explain why it worked, I'll appreciate.

长梦不多时 2024-10-04 00:32:34

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

I don't work with IceFaces, but try to remove immediate="true" from your command link - with standard h:commandLink it could cause the problem.

维持三分热 2024-10-04 00:32:34

它与周期以及事件的处理方式有关。

根据我的经验,有两种方法可以解决此问题:

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

2)通过使用另一个标签进行捕获来解决

Its about the cycle and how the events are handled.

from my experience, two ways to fix it:

1) queue the event (check the different type of events) until its time to update the values.

2) work around by trapping with another tag

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文