【问题标题】:a4j:commandButton is not working. No action is taking place on clicka4j:commandButton 不工作。单击时未执行任何操作
【发布时间】:2012-04-16 23:59:12
【问题描述】:

我正在学习 RichFaces。将 a4j:commandButton 添加到 .xhtml。下面是我的 .xhtml 代码,

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
   <h:head>
   </h:head>

   <h:body>
    <h:form>
     <rich:panel>
         <h:panelGrid column="2">
            <h:inputText value="#{echoBean.name}"/>
            <h:outputText value="#{echoBean.name}" id="echoTxt" />
            <h:outputText value="Count" />
            <h:outputText id="countTxt" value="#{echoBean.count}" />
         </h:panelGrid>
         <a4j:commandButton value="Send" actionListener="#{echoBean.incrementCount}"  reRender="echoTxt, countTxt"/>
     </rich:panel>
     </h:form>
   </h:body>
</html>

我使用的是richfaces 4。所以我没有给出任何a4j过滤器

但是 a4j:commandButton 不起作用。它没有对点击执行任何操作。并且堆栈跟踪没有错误。

我错过了什么吗?

谢谢

更新:

我已将 actionListener 替换为 action。 现在单击按钮会引发以下异常,

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
    at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1560)
    at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:267)
    at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1590)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at javax.faces.component.UIForm.visitTree(UIForm.java:344)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:254)
    at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188)
    at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:453)
    at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

我的托管 Bean 代码是,

/** * */

package org.droidaceapps.src;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

/**
 * @author yasodavenkat
 *
 */
@ManagedBean(name="echoBean")
@SessionScoped
public class EchoBean {

    private String name;
    private int count;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public EchoBean() {
    }

    public void incrementCount(ActionEvent e){
        count = name.length();
    }   
}

我了解这与状态管理问题有关。我的猜测正确吗?我还有什么想念的吗?

谢谢

【问题讨论】:

  • 服务器日志/萤火虫中是否有任何错误?
  • @Daniel - 服务器日志中没有错误。实际上,我期望文本字段中给定字符串的长度显示在 OutputText 中。它发生在普通的命令按钮上。但是如果我使用 a4j:commandButton 它根本不起作用。

标签: jsf richfaces


【解决方案1】:

这些是解决或检查问题解决方案的一些步骤。请注意,由于有关您的项目的信息较少(您的支持 bean 不在这里),这不是完整的解决方案

  1. 尝试 'h' 或 't' 标记并尝试运行它
  2. 检查你的管理 bean 你提到你的 bean 范围把它放在 sessionscope 中

如果这不起作用,请使用您的支持 bean 和 faces-config.xml

【讨论】:

  • 这里 bean 的范围不是问题,因为即使在带有 ApplicationScope 的 bean 上也可以触发该操作
【解决方案2】:

您正在使用actionListener 作为命令按钮,您应该使用action 使其工作。

<a4j:commandButton value="Send" action="#{echoBean.incrementCount}"
    reRender="echoTxt, countTxt"/>

另外,不要忘记通过添加execute 属性标签来设置您要发送的数据。默认情况下,它将提交所有表单。您可以在component documentation找到更多信息,您可以参考online showcase。

更新:

name 变量为空,这就是它抛出该错误的原因。那是因为你在使用。这是因为你正在这样做

<h:inputText value="#{echoBean.name}"/>
<h:outputText value="#{echoBean.name}" id="echoTxt" />

echoBean.name 在您的 bean 中设置了两次,第一次使用 inputText 值(您输入的文本),第二次使用 outputText 值(null)。如果你想要这种行为,你真的应该看看我在我的帖子中添加的展示链接并分析它必须如何完成。

【讨论】:

  • 感谢您的回复。只是看着你的回复,我尝试添加动作而不是 actionListener。这已经发生了点击事件,但它正在引发异常。当然,我认为这与此无关,但您可以帮助我解决这个问题。请查看我在问题中使用托管 Bean 和错误跟踪的更新。
  • 只是在急切地询问......这是该错误背后的原因,然后我在想我使用 h:commandButton 时它是如何工作的。然后自己回答,因为当使用 h:commandButton 时,它正在刷新整个页面,以便这些状态值可用。但是在 a4j 的情况下:如何更新状态?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-23
  • 1970-01-01
  • 1970-01-01
  • 2021-09-15
  • 1970-01-01
  • 1970-01-01
  • 2021-11-26
相关资源
最近更新 更多