来自jsp:include的JSF 1.2自定义组件 [英] JSF 1.2 custom component from jsp:include

查看:94
本文介绍了来自jsp:include的JSF 1.2自定义组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始提出问题之前,这是我不幸的限制:

Before I get started with my question, here are my unfortunate limitations:


  1. 我使用的是JSF 1.2,而不是2;所以没有复合组件。

  2. 我使用JSP进行渲染而不是facelets;所以这些复合组件都没有。

  3. 我不允许使用任何第三方标签库(richFaces,iceFaces等)

这些限制是一成不变的。

These limitations are set in stone.

现在转到我的问题。目前,我们有一个JSP 子视图来处理创建地址。随之而来的是很多javascript以及一个支持bean。此页面永远不会直接使用。相反,它包含使用< jsp:include />

Now moving onto my question. Currently, we have a JSP subview which handles creating an address. There is a lot of javascript that goes along with this, along with a backing bean. This page is never used directly. Instead, it's included using a <jsp:include />.

但是,有几个属性可以我希望能够改变。例如,是否需要县,我们目前正在进行地址清理等。为了做到这一点,使用自定义组件是有意义的(我认为?)。但是,我不确定最好的方法。

However, there are several attributes that I want to be able to change. For instance, is county required, are we currently doing address scrubbing, etc. In order to do this, it would make sense to use a custom component (I think?). However, I'm not really sure the best way to do this.

如果可以的话,我只需将这个JSP变成一个复合组件并完成它。但是,根据我的限制,这不是一个真正的选择。

If I could, I would simply turn this JSP into a composite component and be done with it. However, that's not really an option based on my limitations.

我有什么选择?如果不涉及javascript的数量,这将不会那么困难。我知道我的解释含糊不清;但是,我更多的是寻求指导而非直接回答。我已经使用javascript等搜索了自定义JSF 1.x组件等内容。但是我没有找到很多好文章。

What are my options? This wouldn't be so difficult if it weren't for the amount of javascript involved. I know my explanation was vague; however, I'm looking more for guidance than a direct answer. I've googled for things such as custom JSF 1.x components with javascript, etc. I haven't found many good articles, however.

提前致谢。

推荐答案

创建JSP标记文件。

/WEB-INF/tags/foo.tag

<%@ tag body-content="empty" %>
<%@ attribute name="countryRequired" required="false" type="java.lang.Boolean" %>
<%@ attribute name="showAddress" required="false" type="java.lang.Boolean" %>

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<h:panelGrid columns="2">
    <h:outputLabel for="country" value="Country" />
    <h:inputText id="country" value="#{bean.country}" required="${countryRequired}" />

    <c:if test="${showAddress}">
        <h:outputLabel for="address" value="Address" />
        <h:inputText id="address" value="#{bean.address}" />
    </c:if>
</h:panelGrid>

按如下方式声明和使用它(不需要额外的XML配置):

Declare and use it as follows (no additional XML configuration necessary):

<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
...
<my:foo showAddress="true" />

请注意,JSTL在这里也是一个视图构建时间标签,就像在Facelets中一样。另请注意,您不能使用#{} 来引用JSP标记属性。

Note that JSTL is also here a "view build time" tag like as in Facelets. Also note that you can't use #{} to reference JSP tag attributes.

这篇关于来自jsp:include的JSF 1.2自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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