部署JSF组合组件以供共享使用 [英] Deploy JSF composite components for shared use

查看:106
本文介绍了部署JSF组合组件以供共享使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个计划在未来变得非常大的Java EE项目,我希望尽可能多地共享代码。这不仅包括Java代码,还包括UI元素的代码。我考虑基于明确定义的主题(如用户管理,税收,产品)开发企业组件,这些主题基于消息,bean等进行交互。我还考虑为所有这些组件提供一些托管bean和JSF组合,以提供一些基本功能,供以后在Web UI中使用。这就是上下文......

I work on a Java EE project which is planned to become quite large in future and I want to share as much code as possible. This included not only Java code, but also code for UI elements. I think about developing enterprise components based on clear defined subjects (like user administration, taxes, products) which interact on basis of messages, beans and so on. I also think about giving all these components some managed beans and JSF composites to provide some basic functionality for later use in the web UI. That's the context...

为了使其具体化:假设我有一个EAR(um.ear)用于用户管理。在其中我有一些用于数据库连接的JPA实体(jpa.jar),我有一些企业bean用于基本功能,如身份验证(ejb.jar)。另外,我想在(jsf.jar)中放入另一个jar文件,其中包含一个托管bean LoginController,用于复合组件(带有用户名和密码的输入)login_box.xhtml,我希望稍后将其放入我的Web前端到不同的位置,取决于实际页面。

To make it concrete: Let's say I have an EAR (um.ear) for user management. Within it I have some JPA entities for database connectivity (jpa.jar) and I have some enterprise beans for the basic functionality like authentication (ejb.jar). Additionally, I want to put another jar file in (jsf.jar) which contains a managed bean LoginController for use with a composite component (with an input for username and password) login_box.xhtml which I want to place later into my web front end to different locations, depended on the actual page.

login_box.xhtml:

The login_box.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:e="http://java.sun.com/jsf/composite/login">
<h:head>
    <title>Login Box</title>
</h:head>
<h:body>
    <composite:interface>
    </composite:interface>
    <composite:implementation>
        <h:outputStylesheet library="css" name="login.css" target="head" />
        <div class="login_box">
            <h:form>
                <h:messages />
                <h:panelGrid columns="2" columnClasses="rightAlign,leftAlign">
                    <h:outputText value="Email address:" />
                    <h:inputText label="Email address" value="#{LoginController.email}"
                        required="true" size="8">
                        <f:validator validatorId="emailAddressValidator" />
                        <f:validateLength minimum="5" maximum="128" />
                    </h:inputText>
                    <h:outputText value="Password:" />
                    <h:inputText label="Password" value="#{LoginController.password}"
                        required="true" size="8" />
                </h:panelGrid>
                <h:commandButton action="${LoginController.login()}"
                    value="Login..." />
            </h:form>
        </div>
    </composite:implementation>
</h:body>
</html>

在我的主应用程序中,我想使用JSF模板生成页面,我想放置根据需要将标签登录到页面中。

In my main application I want to work with JSF templates to generate the pages and I want to put the login box with the tag into the pages as needed.

当前设置为:

jsf.jar inside um.ear:
|- META-INF/
|   |- faces-config.xml
|   |- web.xml
|   |- sub-web.xml
|   \- resources
|       \- login
|           \- login_box.xhtml
\- com
     |- inside it the managed bean classes

调用xhtml看起来像:

The calling xhtml looks like:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:e="http://java.sun.com/jsf/composite/login">
<h:head>
    <title>Title</title>
</h:head>
<h:body>
    <e:login_box /> 
</h:body>
</html>

当我以这种方式使用它时,我没有收到任何错误,在我生成的HTML中我看到了而不是想要的登录框。

When I use it that way, I do not get any errors and in my resulting HTML I see the instead of the wanted login box.

当我在一个EAR中执行此操作并将托管bean和JSF内容放入WAR(类转移到WEB中)时EAR里面的-INF / classes和WEB-INF / resources的资源一切正常。但是,我如何部署托管bean和JSF内容以供以后在其他EAR或JAR中使用?我读到/META-INF/faces-config.xml足以强制容器扫描JSF内容。

When I all do this within one EAR and I put the managed beans and the JSF stuff into a WAR (the classes are moved into WEB-INF/classes and the resources to WEB-INF/resources) inside the EAR everything works fine. But, how can I deploy the managed beans and the JSF stuff for later use in other EARs or JARs? I read that the /META-INF/faces-config.xml would be enough to force the container to scan for JSF stuff.

我的faces-config.xml:

My faces-config.xml:

<?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>

我使用JBoss 6.1-Final,我在JAR中尝试了所有可能的位置,这对我来说是合乎逻辑的。我把类和资源目录放到root'/',/ META-INF和WEB-INF。所有这一切都行不通。有没有人有建议,这里有什么问题?

I work with JBoss 6.1-Final and I tried all possible locations inside the JAR which was logical for me. I put the classes and the resource directory to root '/', to /META-INF and to WEB-INF. All of this did not work. Does anyone has suggestions, what is wrong here?

推荐答案

JAR必须在 / WEB里面结束WAR的-INF / lib (可以反过来成为EAR的一部分)。

That JAR has to end up inside /WEB-INF/lib of WAR (which can in turn be part of EAR).

你的JAR文件结构没问题。

Your JAR's file structure is fine.

这篇关于部署JSF组合组件以供共享使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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