0

同様の質問がある多くのページを読んで検索してきましたが、commandButton がアクションを呼び出さない理由がわかりません (デバッグしましたが、それが問題です)。私のコードは単純に見えますが...動作しません。初心者の問題かもしれませんが、どこにあるのかわかりません。

JSF2 と Liferay Faces Alloy を使用して、liferay のポートレットを作成しています。

また、質問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 を使用して、文字列 (必要でなくても) を返すことも試みましたが、何もしませんでした。誰でも私を助けることができますか?どうもありがとう。

4

2 に答える 2

0

宣言で texto を初期化しないのはなぜですか?

private String texto = "Jereje";

public void addGlobalSuccessInfoMessage(){
    //faces message
}

//Getter Setter

その後、PostConstruct メソッド全体を削除できます。また、ナビゲーションなしで文字列を設定して更新するだけの場合は、f:setPropertyActionListener と af:ajax を使用してメッセージを更新します。必要に応じて、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>
于 2016-04-16T03:42:57.017 に答える