0

コンポーネントを保存するためのイベント ハンドラーに取り組んでいます。

私の目的は、ユーザーがスキーマに基づいてコンポーネントを作成するときに、いくつかの検証を実行することです。

「Employee」という名前のスキーマがあります。

Employee には「Experience」という名前の埋め込みスキーマがあり、複数値です。

経験には3つのフィールドがあります。

  1. Role : Manager、Lead の値をドロップダウンします。
  2. 会社名:テキスト欄
  3. 年: テキストフィールド

ユーザーがこれらのフィールドにデータを入力すると、保存する前にいくつかの検証を行いたいと思います。

高レベルの設計は次のようになります。

  1. コンポーネントのインスタンスをロードします
  2. 埋め込みフィールド「エクスペリエンス」に移動します

すべての「体験」のために。「ロール」の値を取得し、他の 2 つのフィールドに適切な値が入力されていることを確認する必要があります (コンポーネントの保存イベントを書き込むことによって)

For( all the repeated "Experience")
{
    If (Role=="Manager")
        check the values in the other two fields and do some validation
    If (Role=="Lead") 
        check the values in the other two fields and do some validation
}

埋め込みフィールドでサブフィールドの値と名前を抽出することに行き詰まっています。

私が試してみました:

Tridion.ContentManager.Session mySession = sourcecomp.Session;
Schema schema= sourcecomp.Schema;
if(schema.Title.Equals("Employee"))
{
    var compFields = new ItemFields(sourcecomp.Content, sourcecomp.Schema);
    var embeddefield = (EmbeddedSchemaField)compFields["Experience"];

    var embeddedfields = (IList<EmbeddedSchemaField>)embeddefield.Values;
    foreach(var a in embeddedfields)
    {
        if(a.Name.Equals("Role"))
        {
            string value=a.Value.ToString();
        }
    }
}

実際、他のフィールドの値を同時に取得する方法に行き詰まっています。

それがどのように行われるかを説明できる人はいますか?

4

1 に答える 1

4

EmbeddedSchemaField クラスについて理解する必要があるのは、それがスキーマとフィールドの両方を表すということです (名前が示すように...)

コンポーネントのフィールドを対象とするコードを作成するときは、コンポーネントのソース XML を参照すると、クラスが実行する必要があることを視覚的に表現するのに役立ちます。次のようなコンポーネント XML を見ると:

<Content>
    <Title>Some Title</Title>
    <Body>
            <ParagraphTitle>Title 1</ParagraphTitle>        
            <ParagraphContent>Some Content</ParagraphContent>
    </Body>
    <Body>
            <ParagraphTitle>Title 2</ParagraphTitle>        
            <ParagraphContent>Some more Content</ParagraphContent>
    </Body>
</Content>        

Body は、複数値を持つ埋め込みスキーマ フィールドであり、その中に 2 つの単一値フィールドが含まれます。

次に、TOM.NET でこれらのフィールドに対処します。

// The Component
Component c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
// The collection of fields in this component
ItemFields content = new ItemFields(c.Content, c.Schema);
// The Title field:
TextField contentTitle = (TextField)content["Title"];
// contentTitle.Value = "Some Title"
// Get the Embedded Schema Field "Body"
EmbeddedSchemaField body = (EmbeddedSchemaField)content["Body"];
// body.Value is NOT a field, it's a collection of fields.
// Since this happens to be a multi-valued field, we'll use body.Values
foreach(ItemFields bodyFields in body.Values)
{
    SingleLineTextField bodyParagraphTitle = (SingleLineTextField)bodyFields["ParagraphTitle"];
    XhtmlField bodyParagraphContent = (XhtmlField) bodyFields["ParagraphContent"];
}

これで始められることを願っています。

于 2012-05-07T13:25:43.457 に答える