调用操作后页面不刷新
我有 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.2 和 IceFaces 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于找到了解决方案。我删除了 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.
我不使用 IceFaces,但尝试从命令链接中删除
immediate="true"
- 使用标准h:commandLink
可能会导致问题。I don't work with IceFaces, but try to remove
immediate="true"
from your command link - with standardh:commandLink
it could cause the problem.它与周期以及事件的处理方式有关。
根据我的经验,有两种方法可以解决此问题:
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