2

Webアプリのページ装飾にsitemeshを使用しています。

textareaフィールドのコンテンツが完全なhtmlページであるフォームがあります。

問題は、Sitemeshがこのページを解析するときに、textareaフィールドからタイトル、頭、本文を抽出し、それでページを装飾することです。

<textarea name="page_content">
    <!-- tags below should not be parsed by Sitemesh -->
    <html>
         <head>...</head>
         <body>...</body>
    </html>
</textarea>

Sitemeshページパーサーは、ページ内でこれらのタグがすでに表示されていることを認識しているようです。

Sitemeshがテキストエリアのコンテンツを解析しないようにする方法について何かアイデアはありますか?

4

2 に答える 2

2

自分で解決しました。HTMLPageParserのソースコードを調べると、解決策は自明です。

秘訣は、独自のルールセットを使用して新しい状態を追加するカスタムPageParserを作成することです。つまり、ルールはまったくありません。

public class CustomPageParser extends HTMLPageParser {

    @Override
    protected void addUserDefinedRules(State html, PageBuilder page) {
        super.addUserDefinedRules(html, page);
        // Ensure that while in <textarea> tag, none of the other rules kick in.
        State textarea = new State();
        html.addRule(new StateTransitionRule("textarea", textarea));

    }
}
于 2010-03-07T09:29:05.240 に答える
1

You can't put <tags> inside a textarea. It is completely invalid. Textarea elements are not ‘CDATA elements’ like <script> and <style>, any < you put inside them is real markup and not a string literal.

In practice browsers will usually let you get away with it (until you try to include another textarea inside, of course), but what you should be writing is:

<textarea name="page_content">
    &lt;html>
        ...
    &lt;/html>
</textarea>
于 2010-03-07T09:37:44.577 に答える