Java EE6>将 JSF facelets (xhtml) 和 ManagedBeans 打包为 JAR [英] Java EE6> Packaging JSF facelets (xhtml) and ManagedBeans as JAR

查看:26
本文介绍了Java EE6>将 JSF facelets (xhtml) 和 ManagedBeans 打包为 JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 JSF facelets 和 ManagedBeans 打包到 JAR 文件中?以便我们可以在不同的 war/ear 项目中使用此代码和 UI 组合?

Is it possible to package JSF facelets and ManagedBeans into a JAR file? So that we can use this code and UI combination in different war/ear projects?

我不是在谈论 JSF 组件!

I am not talking about JSF Components!

如果是 - 你能给我指点教程或博文

If yes - can you point me to a tutorial or blog post

我需要有关 Jar 结构的详细信息以及 Jar 中所需的其他文件?

I need details about the Jar structure and additional files needed in the Jar?

谢谢马克斯

推荐答案

是的,这绝对有可能,假设您使用的是 JSF 2.0(Java EE 6 的一部分).

Yes, that's definitely possible, assuming that you're using JSF 2.0, part of Java EE 6.

对于托管 bean 和其他 JSF 类,如验证器、转换器等,只需使用 @ManagedBean@FacesValidator@FacesConverter 等,并以通常的方式将它们打包在 JAR 中.您只需要在 JAR 中提供与 JSF 2.0 兼容的 /META-INF/faces-config.xml 文件.

As to the managed beans and other JSF classes like validators, converters, etc, just annotate them with @ManagedBean, @FacesValidator, @FacesConverter, etc and package them in the JAR the usual way. You only need to provide a JSF 2.0 compatible /META-INF/faces-config.xml file in the JAR.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
</faces-config>

这种方式将触发 JSF 扫描 JAR 中的类以查找 JSF 特定的注释.或者,您也可以按照 JSF 1.x 的方式在 JAR 的 faces-config.xml 中注册它们.

This way JSF will be triggered to scan the classes in the JAR for JSF specific annotations. Alternatively you can also just register them in the JAR's faces-config.xml the JSF 1.x way.

对于 Facelets 资源,只需将它们放在 JAR 的 /META-INF/resources 文件夹中即可.它将以与 WAR 的公共网页内容相同的方式处理.

As to Facelets resources, just drop them in /META-INF/resources folder of the JAR. It'll be treated the same way as public webcontent of the WAR.

这篇关于Java EE6>将 JSF facelets (xhtml) 和 ManagedBeans 打包为 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆