0

(単純な) JSF 2 カスタム コンポーネントを使用しています。

次のようなtaglib.xmlファイルを使用していることを意味します。

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib id="sentest"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0"
>
    <namespace>http://www.senat.fr/taglib/sentest</namespace>

[...]
    <tag>
        <description>
            <![CDATA[
            À COMPLÉTER
            ]]>
        </description>
        <tag-name>senMandats</tag-name>
    <source>tags/sen/senMandats.xhtml</source>
        <attribute>
            <description>
                <![CDATA[
        Identifiant unique.
        ]]>
            </description>
            <name>id</name>
            <required>true</required>
            <type>java.lang.String</type>
        </attribute>
        <attribute>
            <description>
                <![CDATA[
     Contexte de sélection du Sénateur.
    ]]>
            </description>
            <name>context</name>
            <required>true</required>
        </attribute>
    </tag>
</facelet-taglib>

コンポーネントは、UI コンポジションを使用して定義されます。

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="fr"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:p="http://primefaces.org/ui"
    xmlns:sen="http://java.sun.com/jsf/composite/sen"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:sf="http://www.senat.fr/taglib/senfunctions"
    xmlns:st="http://www.senat.fr/taglib/sentest"
    xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions">
    <h:head/>
    <h:body>
        <ui:composition>
    [...]
        </ui:composition>
    </h:body>
</html>

1 つの非常に恥ずかしい点を除いて、正常に動作します。

これらのカスタム コンポーネントに動的な el 値を渡しています。

例 :

<st:senMandats id="toto" context="#{selectionContext}"/>

別の場所で定義されている selectionContext Bean。

st:senMandats では、ネストされた方法で他のカスタム コンポーネントを使用します。何かのようなもの :

<st:listeMandats mandatContext="#{sensContext}" asen="#{selectionContext.selectedSen}"/>

listeMandat コンポーネントは、primefaces dataTable を使用して、コンテキストからいくつかのリストを表示します。だから、私は次のようなコードを持っています:

<h:outputLabel value="listeMandats de #{asen.libelleLong}" styleClass="bigTitleMandats" rendered="#{not empty asen}" />
<p:dataTable id="tableMandatsSenatoriaux" value="#{mandatContext.asList}" /* lots of other parameters */>

ピッカーでエントリを選択すると、カスタム コンポーネントが適切に更新されます。h:outputLabel によって valueDisplayed が選択に応じて正しく更新されていることがわかります。

#{mandatContext.AsList} が呼び出されると、アプリケーション コンテキストから #{asen} を取得し、要求されたリストを返す前に内部更新を実行します。問題があります: #{asen.libelleLong} をレンダリングするときに #{asen} が問題ないように見える場合、バッキング Bean から更新された値を取得できません。

私は次の機能を使用しています:

@SuppressWarnings("unchecked")
public static <T> T findBean(String name) {
    if ((name == null) || name.isEmpty())
        return null;
    FacesContext fc = FacesContext.getCurrentInstance();
    logger.debug("Retrieving #{" + name + "}");
    return (T) fc.getApplication().evaluateExpressionGet(fc,
            "#{" + name + "}", Object.class);
}

AsList メソッドで:

JSFUtils.findBean("#{asen}")

更新されていない古い値を常に返します。

Bean が更新された値にアクセスできるようにするにはどうすればよいですか? http://www.mkyong.com/jsf2/access-a-managed-bean-from-event-listener-jsf/で mykong によって提案されたソリューション 4、5、および 6 を試しましたが、それでも正しい値が得られません。

特定のクラスから派生したカスタム コンポーネント クラスをコーディングする必要がありますか? その場合、レンダラーもコーディングする必要がありますか? xhtmlファイルにレイアウトがあることを感謝しているので、それを避けたいと思います。

前もって感謝します。

私は使っている :

  • プライムフェイス 3.4.1
  • CODI 1.0.5
  • OpenWebBeans 1.1.6
  • マイフェイス 2.1.9
  • Tomcat 7.0.32 (編集:「追加の質問」を別の質問として設定)
4

0 に答える 0