Oracle ADF h:commandButton f:ajax 不起作用

发布于 2024-12-16 19:29:24 字数 1349 浏览 3 评论 0原文

尝试通过 Ajax 更新页面。单击按钮并在页面上打印出计数器。

以下代码在 Tomcat 7 上与 JSF 2.0 mojarra 一起部署时有效。当从 JDeveloper 11g 部署到内置 Weblogic 服务器时,它不起作用。计数变量确实会增加,但每次使用 ADF 时都会重新加载页面。

支持 Bean:

import javax.faces.bean.*;
import javax.faces.event.ActionEvent;

@ManagedBean(name="countBean")   
@SessionScoped
public class CountBean {
    Integer count=1;
    public void incrementCount(ActionEvent event) {
        ++count;
    }
    public Integer getCount() { return count;}
    public void setCount(Integer count) {   this.count = count; }           
}

JSF 页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
<h:head><title>Ajax commandButton test</title></h:head>
<h:body>
<h3>Ajax count</h3>
<h:form>
<h:commandButton id="cb" value="Increment count" 
   actionListener="#{countBean.incrementCount}">
    <f:ajax event="click" execute="cb" render="ot" />
</h:commandButton>
<br/><br/>
Counter = <h:outputText id="ot" value="#{countBean.count}"/>
</h:form>
</h:body>
</html>

Trying to update a page through Ajax. Click a button and print out a counter on the page.

The following code works when deployed with JSF 2.0 mojarra on a Tomcat 7. It does not work when deployed from JDeveloper 11g to the built in Weblogic server. The count variable does get incremented, but the page is reloaded each time when using ADF.

Backing Bean:

import javax.faces.bean.*;
import javax.faces.event.ActionEvent;

@ManagedBean(name="countBean")   
@SessionScoped
public class CountBean {
    Integer count=1;
    public void incrementCount(ActionEvent event) {
        ++count;
    }
    public Integer getCount() { return count;}
    public void setCount(Integer count) {   this.count = count; }           
}

JSF-page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
<h:head><title>Ajax commandButton test</title></h:head>
<h:body>
<h3>Ajax count</h3>
<h:form>
<h:commandButton id="cb" value="Increment count" 
   actionListener="#{countBean.incrementCount}">
    <f:ajax event="click" execute="cb" render="ot" />
</h:commandButton>
<br/><br/>
Counter = <h:outputText id="ot" value="#{countBean.count}"/>
</h:form>
</h:body>
</html>

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

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

发布评论

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

评论(1

高冷爸爸 2024-12-23 19:29:24

我自己找到了答案:

<af:commandButton text="increment count" id="cb1" actionListener="#{countBean.incrementCount}" partialSubmit="true"/>

Counter = <af:outputText id="ot" value="#{countBean.count}" partialTriggers="cb1"/>

I found the answer myself:

<af:commandButton text="increment count" id="cb1" actionListener="#{countBean.incrementCount}" partialSubmit="true"/>

Counter = <af:outputText id="ot" value="#{countBean.count}" partialTriggers="cb1"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文