bean的定义很简单,如下所示:
@Named
@RequestScoped
public class ConfirmBean {
private String confirmMsg;
public ConfirmBean(){
confirmMsg = "Are you sure you want to delete this file ?";
}
// getters & setters
}
和继承的类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()+"');";
}
}
使用 taglib 文件-
<namespace>http://www.custom.tags/jsf/delete</namespace>
<tag>
<tag-name>confirmDelete</tag-name>
<behavior>
<behavior-id>confirm</behavior-id>
</behavior>
</tag>
有一个条目,context-param
如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.1
Mojarra 2.2.12
我这里有一个NPE
-