我一直在阅读和搜索许多有类似问题的页面,但我找不到为什么我的 commandButton 没有调用该操作(我已经对其进行了调试,这就是问题所在)。我的代码看起来很简单,但是......不起作用。也许这是一个新手问题,但我不知道它在哪里。
我正在使用 JSF2 和 Liferay Faces Alloy 为 liferay 编写一个 portlet。
我还阅读了commandLink/commandButton/ajax backing bean action/listener method not invoked的问题,这对我来说很有教育意义,但这些都没有解决我的问题。
这是我的 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 返回一个字符串(甚至没有必要),但什么也没有。有谁能够帮我?非常感谢。