2

私はタペストリーの経験があまりないので、どこから始めたらいいのかよくわかりません。

Insert コンポーネントを新しいコンポーネント (NewInsert など) で拡張する必要があります。これは、挿入されるものに特定の CSS クラスを適用します。どうすればいいですか?

私は基本的に、のようなものを生成するものになりたいと思ってい<span class="myClass">The value</span>ます。

Insert を拡張して行うのはなぜですか? アプリケーションはほぼ完成しましたが、Insert を使用するすべての場所でこの CSS クラスが必要であることに気付きました。すべてのファイルで、'type="Insert">' を 'type="NewInsert">' にグローバルに置換するだけです。

4

2 に答える 2

2

私が望んでいたことを達成するには、Insert のrenderComponentメソッドをオーバーライドする必要がありました。setStyleClassこれは、Tapestry 4.0.2 にメソッドがないためです。基本的に似てた

    if (!cycle.isRewinding()) {
      Object value = getValue();

      if (value != null) {
        String styleClass;
        String insert = null;
        Format format = getFormat();

        if (format == null) {
          insert = value.toString();
        }
        else {
          insert = format.format(value);
        }

        styleClass = getStyleClass();

        if (styleClass == null) {
          /* No classes specified */
          styleClass = MY_CLASS;
        }
        else {
          /* Append the preserveWhiteSpace class to the string listing the style classes. */
          styleClass += " " + MY_CLASS;
        }

        if (styleClass != null) {
          writer.begin("span");
          writer.attribute("class", styleClass);

          renderInformalParameters(writer, cycle);
        }

        writer.print(insert, getRaw());

        if (styleClass != null) {
          /* </span> */
          writer.end();
        }
      }
    }
  }

setStyleClass メソッドがあれば、すぐに実行できたはずです

setStyleClass(MY_CLASS);
super.renderComponent;
于 2009-06-23T14:42:16.220 に答える
0

Insert をオーバーライドする理由 独自の InsertSpan コンポーネントを作成してみませんか? Insert のソースを見るだけで、それがいかにシンプルであるかがわかります。自由にカット アンド ペーストしてください。オープン ソースです。

いっそのこと、Tapestry 5 へのアップグレードを検討してください。Tapestry 4 は約 4 年間積極的に開発されていません。

于 2012-10-16T18:00:14.400 に答える