[英]commandButton doesn't invoke managed bean action
我一直在阅读和搜索具有类似问题的许多页面,但是我无法找到为什么我的commandButton没有调用该动作的原因(我已经调试了它,这就是问题所在)。 我的代码看起来很简单,但是...不起作用。 也许这是一个新手问题,但我不知道它在哪里。
我正在使用JSF2和Liferay Faces Alloy为liferay编写portlet。
我还阅读了未调用commandLink / commandButton / ajax支持bean动作/侦听器方法的问题 ,对我来说非常有教育意义,但没有任何要点解决了我的问题。
这是我的mainView.xhtml文件:
<?xml version="1.0"?>
<f:view
xmlns="http://www.w3.org/1999/xhtml"
xmlns:aui="http://liferay.com/faces/aui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<h:form>
<h:messages globalOnly="true" layout="table" />
<h:outputText id="esteTexto" value="#{ramSession.texto}" />
<br />
<h:commandButton action="#{ramSession.add}" styleClass="btn btn-default" value="#{ramSession.texto}">
</h:commandButton>
</h:form>
</h:body>
</f:view>
这是我的SessionScoped ManagedBean文件RamSession.java:
@ManagedBean
@SessionScoped
public class RamSession extends AbstractBaseBean implements Serializable {
private static final long serialVersionUID = 919724848720360000L;
private String texto;
public void add() {
this.texto = new String("Entrando");
}
@PostConstruct
public void postConstruct() {
this.texto = new String("Jereje");
}
public String getTexto() {
logger.info("gettingTexto");
addGlobalSuccessInfoMessage();
return this.texto;
}
public void setTexto(String texto) {
this.texto = texto;
}
}
我也尝试过使用ActionListener方法甚至使用ajax返回一个String(甚至不是必需的),但是什么也没有。 有谁能够帮助我? 非常感谢。
也许您的mojarra列表器配置不正确。
请执行以下两个子步骤之一
一种。 通过将以下代码添加到每个pom.xml中,在每个Liferay JSF项目中添加liferay-faces-init.jar依赖项:
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-init</artifactId>
<version>3.1.3-ga4</version>
</dependency>
b。 在所有JSF项目的每个WEB-INF / web.xml中添加以下代码:
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
为什么不在声明中初始化texto?
private String texto = "Jereje";
public void addGlobalSuccessInfoMessage(){
//faces message
}
//Getter Setter
然后,您可以删除整个PostConstruct方法。 同样,如果您只想设置一个字符串并在没有导航的情况下进行更新,则只需将f:setPropertyActionListener与af:ajax一起使用即可更新您的消息。 如果需要,可以使用action,方法是返回null或void,或者可以返回actionListener并在其中设置字符串,但是我不知道为什么要这么做。 该链接可能会帮助您解决这些问题。Balus C回答 。 可能还希望从getter方法中删除任何多余的逻辑。 这不会影响您的问题,但会更清洁,在吸气剂上创建成功消息似乎很麻烦。
<h:form id="myForm">
<h:messages globalOnly="true" layout="table" />
<h:outputText id="esteTexto" value="#{ramSession.texto}" />
<br />
<h:commandButton value="#{ramSession.texto}" actionListener="#{ramSession.addGlobalSuccessInfoMessage()}" styleClass="btn btn-default">
<f:setPropertyActionListener value="Entrando" target="#{ramSession.texto}" />
<f:ajax render="myForm" />
</h:commandButton>
</h:form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.