2
2

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 5 years have passed since last update.

Client Behaviorを作成する

Last updated at Posted at 2015-04-07

http://jsfcorner.blogspot.jp/2013/02/client-behavior-functionality-with-jsf.html
を参考にBehaviorを実装してみたがbehavior-classが見つからないエラーが発生してしまう。

エラー
javax.faces.FacesException: Could not find any registered behavior-class for behaviorId : confirmation
	at org.apache.myfaces.application.ApplicationImpl.createBehavior(ApplicationImpl.java:1182)
	at javax.faces.application.ApplicationWrapper.createBehavior(ApplicationWrapper.java:113)
	at org.apache.myfaces.view.facelets.tag.jsf.BehaviorTagHandlerDelegate.createBehavior(BehaviorTagHandlerDelegate.java:102)
	at org.apache.myfaces.view.facelets.tag.jsf.BehaviorTagHandlerDelegate.applyAttachedObject(BehaviorTagHandlerDelegate.java:137)
	at org.apache.myfaces.view.facelets.tag.jsf.BehaviorTagHandlerDelegate.apply(BehaviorTagHandlerDelegate.java:71)

以下は上記サイトを参考に実装した内容。

ConfirmBehavior.java
@FacesBehavior(value = "confirmation")
public class ConfirmBehavior extends ClientBehaviorBase {
    @Override
    public String getScript(ClientBehaviorContext behaviorContext) {
        return "return confirm('Are you sure ?');";
    }
}
taglib.xml
<namespace>http://www.rubus.be/jsf/tutorial</namespace>
<tag>
    <tag-name>confirmation</tag-name>
    <behavior>
        <behavior-id>confirmation</behavior-id>
    </behavior>
</tag>
confirm.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:r="http://www.rubus.be/jsf/tutorial"
...
<h:commandButton value="with confirmation" actionListener="#{bean.performAction}">
    <r:confirmation/>
</h:commandButton>
...
</html>

ConfirmBehavior.javaがbehaiviorとして読み込まれていないのが原因のようだったので、faces-config.xmlに追加してみたらうまくいった。

faces-config.xml
<behavior>
	<behavior-id>confirmation</behavior-id>
	<behavior-class>xxx.ConfirmBehavior</behavior-class>
</behavior>
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?