我一直在閱讀和搜索具有類似問題的許多頁面,但我找不到爲什麼我的commandButton沒有調用動作(我調試過它,這是問題)。我的代碼看起來很簡單,但...不起作用。也許這是一個新手問題,但我不知道它在哪裏。commandButton不會調用託管bean動作
我正在寫一個使用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,但沒有。有誰能夠幫助我?非常感謝。
所以,當你刪除'',它開始工作?如果不是,爲什麼它包含在問題中? –
BalusC
我刪除了但它無法正常工作。 我不理解你是什麼意思,當你問爲什麼它包含在問題中時,我只希望它在沒有工作時出現。評估 感謝您的時間! :) –
ferda
通過這種方式,您可以進一步降低可能的原因,並通過減少不會導致問題的干擾噪音來改善您的問題。 – BalusC