0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

<f:ajax> Unable to attach <f:ajax> to non-ClientBehaviorHolder parentとなった時の対応方法

Posted at
  • 環境
    • CentOS Linux release 7.8.2003 (Core)
    • Eclipse IDE for Enterprise Java Developers.Version: 2020-03 (4.15.0)
    • openjdk version "11.0.7" 2020-04-14 LTS
    • JSF 2.3.9

事象 : ajaxの処理を追加してページを表示しようとしたらHTTPSステータス500になった

EclipseのConsoleのエラー
javax.faces.view.facelets.TagException: /base.xhtml @18,103 <f:ajax> Unable to attach <f:ajax> to non-ClientBehaviorHolder parent
    at com.sun.faces.facelets.tag.jsf.core.AjaxHandler.applyNested(AjaxHandler.java:276)
    at com.sun.faces.facelets.tag.jsf.core.AjaxHandler.apply(AjaxHandler.java:148)
    at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
    at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:179)
...省略...
base.xhtml
...省略...
<h:inputHidden id="file">
  <f:ajax event="change" execute="@form" render="@form" listener="#{uploadBean.uploadFile}" />
</h:inputHidden>
...省略...

原因 : f:ajaxはClientBehaviorHolderインタフェースを実装したタグ内でないと使えないから

Register an AjaxBehavior instance on one or more UIComponents implementing the ClientBehaviorHolder interface.
ajax(JSF 2.2 View Declaration Language: Facelets Variant)

(ざっくり訳)ClientBehaviorHolderインタフェースを実装する1つまたは複数のUIComponentsにAjaxBehaviorインスタンスを登録します。
今回の場合は、h:inputHiddenがClientBehaviorHolderインタフェースを実装しているかが問題だが、ClientBehaviorHolderのJavaDocを見たら対象外だった・・・

All Known Implementing Classes:
HtmlBody, HtmlCommandButton, HtmlCommandLink, HtmlDataTable, HtmlForm, HtmlGraphicImage, HtmlInputFile, HtmlInputSecret, HtmlInputText, HtmlInputTextarea, HtmlOutcomeTargetButton, HtmlOutcomeTargetLink, HtmlOutputLabel, HtmlOutputLink, HtmlPanelGrid, HtmlPanelGroup, HtmlSelectBooleanCheckbox, HtmlSelectManyCheckbox, HtmlSelectManyListbox, HtmlSelectManyMenu, HtmlSelectOneListbox, HtmlSelectOneMenu, HtmlSelectOneRadio
ClientBehaviorHolder (JavaServer Faces API (2.2))

対応 : タグをh:inputTextに変更する

...省略...
<h:inputText id="file" style="display:none;">
  <f:ajax event="change" execute="@form" render="@form" listener="#{uploadBean.uploadFile}" />
</h:inputText>
...省略...
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?