2016-06-14 74 views
1

豆子被定义为简单如下:扩展ClientBehaviorBase的类是否可以视为注入目标?

@Named 
@RequestScoped 
public class ConfirmBean { 

    private String confirmMsg; 

    public ConfirmBean(){ 
     confirmMsg = "Are you sure you want to delete this file ?"; 
    } 

    // getters & setters   
} 

和类与标签库文件 -

<namespace>http://www.custom.tags/jsf/delete</namespace> 
    <tag> 
     <tag-name>confirmDelete</tag-name> 
     <behavior> 
      <behavior-id>confirm</behavior-id> 
     </behavior> 
    </tag> 

与条目作为context-param继承ClientBehaviorBase

@FacesBehavior(value = "confirm") 
public class ConfirmDeleteBehavior extends ClientBehaviorBase { 

    @Inject 
    ConfirmBean confirmBean; 
    //@Inject 
    //ConfirmEJBBean confirmEJBBean; 
    //@EJB 
    //ConfirmEJBBean confirmEJBBean; 

    @Override 
    public String getScript(ClientBehaviorContext behaviorContext) { 
     return "return confirm('"+confirmBean.getConfirmMsg()+"');"; 
    } 
} 

web.xml -

<context-param> 
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name> 
    <param-value>/WEB-INF/taglib/delete.taglib.xml</param-value> 
</context-param> 

和访问在前面这个自定义标签层 -

 <h:form> 
      <h:commandButton value="Delete" action="done"> 
       <b:confirmDelete/> 
      </h:commandButton> 
     </h:form> 

我使用Glassfish应用服务器4.1.1Mojarra 2.2.12版本正在内部使用。

我得到了NPE这里 -

enter image description here

+0

你的标签顺便说一句那种暗示它在MyFaces的工作(由于加钻嘴鱼科标签)和如在JBoss中(由于GlassFish标签)。至少,我总是阅读标签... – Kukeltje

回答

相关问题