質問

私は私が私のJSF / Seamアプリケーションで使用したいJSPタグを持っています。誰かが私にタグを受け入れるように私の環境を得ることにいくつかのガイダンスを与えてもらえます。私はちょうど私の古いタグでfaclets * .taglib.xmlファイルを指すことができますか私は多分、以前のタグを拡張するコンポーネントを記述する必要があるのですか?

すべての情報について

乾杯、 リー

役に立ちましたか?

解決

私は試してみて、直接JSPのコンテキスト外でJSPタグを呼び出すことは非常に消極的になります。 ドキュメントはに、JSP間の類似性を指摘しているようにそして、Faceletsのはかなり表面的です。

一つハック(私はすべてのソリューションをハックになるだろうと思われる)サーブレットAPIにダウンキャストしてJSPを含めることかもしれません。

この機能はする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);
    }
  }

}

この関数は、のWEB-INF / Faceletsを/ include.taglib.xml のにfaceletタグライブラリファイルで定義されています

<?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のの<のhref = "https://facelets.dev.java.net/nonav/docs/dev/docbookでライブラリとして指定されています。 htmlの#設定-webappの-INIT」のrel = "nofollowをnoreferrer">コンテキストパラメータを使用します:

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

JSPを含んにfaceletます:

<!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')を含むデモ}

$の使用に注意してください。デモは= "のhttp://デモ" の機能は、属性ののxmlnsによって含まれます。リクエストスコープの変数のFOO は、テキストフィールドにバインドし、JSPによってピックアップされます。

<時間>

私はこれについて言うことができるすべては、それが私のために働いて、それはタグの特定の組み合わせで、またはJSFライブラリの特定の組み合わせでは動作しませんなぜダースの理由は、おそらくがあるということです。買主の危険負担ます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top