我有一个JSP标签,我想用在我的JSF/缝应用程序。可能有人,请给我一些指导得到我的环境,以接受的标签。我可以点一个faclets*.taglib.xml 文件在我的旧的标签,或者,我需要写入一组分延伸以前的标签也许?

欢呼声的任何信息, 李

有帮助吗?

解决方案

我将非常不愿意尝试和直接援引JSP标签之外JSP的上下文。作为 文件指出, ,相似之处JSP和客户端是很肤浅的。

一个黑客(I嫌疑人,任何解决办法将是一个黑)可能包括JSP通过浇铸下servlet API。

这个功能包括一个给定资源的使用 调用requestdispatcher:

public class Includer {

  public static String include(String resource) {
    FacesContext context = FacesContext
        .getCurrentInstance();
    ExternalContext ext = context.getExternalContext();
    include(ext.getContext(), ext.getRequest(), ext
        .getResponse(), resource);
    return "";
  }

  private static void include(Object context,
      Object request, Object response, String resource) {
    ServletContext servletContext = (ServletContext) context;
    ServletRequest servletRequest = (ServletRequest) request;
    ServletResponse servletResponse = (ServletResponse) response;
    RequestDispatcher dispatcher = servletContext
        .getRequestDispatcher(resource);
    try {
      dispatcher.include(servletRequest, servletResponse);
    } catch (IOException e) {
      throw new FacesException(e);
    } catch (ServletException e) {
      throw new FacesException(e);
    }
  }

}

这个功能的定义是在一个Facelet标签库的文件 WEB-INF/facelets/include.taglib.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib xmlns="http://java.sun.com/JSF/Facelet">
  <namespace>http://demo</namespace>
  <function>
    <function-name>include</function-name>
    <function-class>inc.Includer</function-class>
    <function-signature>
      java.lang.String include(java.lang.String)
    </function-signature>
  </function>
</facelet-taglib>

这个被指定为一个图书馆 WEB-INF/web.xml 使用上下文参数:

  <context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>/WEB-INF/facelets/include.taglib.xml</param-value>
  </context-param>

例的使用

JSP包括在内, includeme.jsp:

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
  <jsp:directive.page language="java"
    contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
  <b>Some data: ${foo}</b>
</jsp:root>

Facelet,包括JSP:

<!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:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:demo="http://demo">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JSP include hack</title>
</head>
<body>
<h:form>
  <p> ${demo:include('/includeme.jsp')} </p>
  <h:inputText type="text" value="#{foo}" />
  <h:commandButton type="submit" />
</h:form>
</body>
</html>

注意使用 ${演示:包括('/includeme.jsp')} 援引的请求调度员(本功能返回的一个空String)。该功能包含的特性 在:演示="http://demo".该请求的范围的变量 foo 必要的文字领域和选取JSP。


所有我可以说这是它的工作对我来说,大概有十几个原因为什么它不工作的某些组合的标签,或与某些组合的JSF库。买者自负。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top