【发布时间】:2016-04-15 13:06:02
【问题描述】:
我一直在阅读和搜索许多有类似问题的页面,但我找不到我的 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,但什么也没有。有谁能够帮助我?非常感谢。
【问题讨论】:
-
那么,当你删除
<c:choose><c:when><c:otherwise>,它就开始工作了?如果不是,为什么它会包含在问题中? -
我删除了两个
但它无论如何都不起作用。当您问为什么将其包含在问题中时,我不明白您的意思,我只希望它在没有工作时出现Assessment 感谢您的时间! :) -
通过这种方式,您可以进一步确定潜在原因并通过减少不会导致问题的干扰噪音来改善您的问题。
-
好的,对不起,你是对的 :) 我正在尝试以这种方式解决它。也许缺少一些 ui 组件?我找不到问题的原因
-
更新:经过一次又一次的测试,我意识到代码没问题。 .xml 文件中可能有一些错误的配置或声明,但我找不到它。我用相同的代码开始了一个新项目,它可以工作。如果有人想测试我已经保存了整个 Eclipse 项目,我会在某一天回到问题上来搜索问题所在。
标签: jsf jsf-2 liferay commandbutton method-invocation