AJAXクライアントの動作を含むコンポーネントを開発しています。動作は、コンポーネントに提供されるパラメーターによって異なります(たとえば、ターゲットのレンダリングと実行)。パフォーマンス上の理由から、フェースレットベースの複合コンポーネントを使用してコンポーネントを実現したくありません。
私の質問は、クライアントの動作をコンポーネントに追加するタイミングです。メソッドを呼び出すとaddClientBehavior()、inをencodeBegin()受け取ります。構築時に動作を追加すると、ajaxリクエストは機能しますが、パラメーターはまだ使用できません。動作を適切に追加する適切な方法またはイベントはありますか?NullPointerExceptionUIComponentBase.restoreBehaviorsState()
私はmojarra2.1.7を使用しています。以下は、動的なajaxのものを含まない私のコンポーネントの短い例です。
@FacesComponent(value="simpleTestLink")
public class SimpleTestLink extends HtmlCommandLink{
    private Logger logger=LoggerFactory.getLogger(getClass());
    private AjaxBehavior ajax;
    enum PropertyKeys{aProp};
    public SimpleTestLink() {
        logger.debug("SimpleTestLink created");
        // adding ajax here works, but no parameters available yet
        ajax = new AjaxBehavior();
        ajax.setExecute(Arrays.asList(new String[]{"@this"}));
        ajax.setRender(Arrays.asList(new String[]{"@form"}));
        addClientBehavior(getDefaultEventName(), ajax);
    }
    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        logger.debug("encodeBegin num: " + getAttr());
        // adding ajax here fails
        super.encodeBegin(context);
    }
    @Override
    public boolean getRendersChildren() {
        return true;
    }
    @Override
    public void encodeChildren(FacesContext context) throws IOException {
        Object attr = getAttr();
        HtmlOutputText outputText = new HtmlOutputText();
        outputText.setValue("testlink["+ attr+"]\n");
        outputText.encodeAll(context);
        super.encodeChildren(context);
    }
    private Object getAttr() {
        return getAttributes().get(PropertyKeys.aProp.name());
    }
}
助けてくれてありがとう、
イェンス