2012-01-16 5 views
1

私は問題を抱えており、XFormsの経験が不足しているだけであることを願っています。私は、列挙 'はい'/'いいえ'として定義されているデータのチェックボックス項目を作成する必要があります。基本的にブール値ですが、別の値のペアがあります。私はすでにやることができましたことは基本的になく、モデル内の余分なデータノードを必要とする作品の何かである:'true'/'false'ではなく 'yes'/'no'の値を持つチェックボックス項目を作成する方法は?

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms" 
    xmlns:f="http://orbeon.org/oxf/xml/formatting" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" 
    xmlns:ev="http://www.w3.org/2001/xml-events" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    > 

    <xhtml:head> 
     <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model"> 
      <xforms:instance id="instance"> 
      <main> 
       <Boolean>true</Boolean> 
       <YesNo>Yes</YesNo> 
      </main> 
      </xforms:instance> 
      <xforms:bind ref="Boolean" type="xsd:boolean" /> 
      <xforms:bind ref="YesNo" constraint=". = 'Yes' or . = 'No'" /> 
     </xforms:model> 
    </xhtml:head> 
    <xhtml:body> 
     <xforms:input ref="instance('instance')/Boolean"> 
     <xforms:label>Boolean: </xforms:label> 
     <xforms:action ev:event="xforms-value-changed"> 
      <xforms:setvalue ref="instance('instance')/YesNo" value="if (instance('instance')/Boolean = 'true') then 'Yes' else 'No'" /> 
     </xforms:action> 
     </xforms:input> 
     <br/> 
     <xforms:output ref="instance('instance')/Boolean"> 
     <xforms:label>Boolean:</xforms:label> 
     </xforms:output> 
     <br/> 
     <br/> 
     <xforms:select ref="instance('instance')/YesNo" appearance="full"> 
     <xforms:label>Yes/No: </xforms:label> 
     <xforms:item> 
      <xforms:label></xforms:label> 
      <xforms:value>Yes</xforms:value> 
     </xforms:item> 
     <xforms:action ev:event="xforms-value-changed"> 
      <xforms:setvalue ref="instance('instance')/YesNo" value="if (instance('instance')/YesNo = 'Yes') then 'Yes' else 'No'" /> 
     </xforms:action> 
     </xforms:select> 
     <br/> 
     <xforms:output ref="instance('instance')/YesNo"> 
     <xforms:label>Yes/No:</xforms:label> 
     </xforms:output> 
    </xhtml:body> 
</xhtml:html> 

この例では、2つの可能な解決策が含まれています: ファーストアクションとブールインスタンスノードにバインドされた標準のブール値のチェックボックスであります2番目のノードの 'Yes'/'No'の値を設定します。このソリューションは正常に動作しますが、スキーマのために作成できない2番目のデータノードが必要です(上記の例では一般的に2番目のインスタンスを作成してこの値を保存できますが、実際のプロジェクトではこれらのチェックボックスは繰り返しブロックになります。値は非常に複雑です)、 2番目は、値が「はい」の選択項目と、空の値が設定されているときに「いいえ」の値を設定しようとするアクションです(選択されていない項目)。不幸にも、この項目を選択解除すると、もう一度選択できなくなります(自動的に選択解除されます)。そのような問題の解決策はありますか?場合

事前に感謝、これはあなたの問題を解決し

答えて

3

・ホープ..

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms" 
    xmlns:f="http://orbeon.org/oxf/xml/formatting" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" 
    xmlns:ev="http://www.w3.org/2001/xml-events" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    > 

    <xhtml:head> 
     <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model"> 
      <xforms:instance id="instance"> 
      <main> 
       <Boolean value="true">Yes</Boolean> 
      </main> 
      </xforms:instance> 
      <xforms:bind ref="Boolean/@value" type="xforms:boolean" readonly="false()" /> 
      <xforms:bind ref="Boolean" calculate="if(@value=true()) then 'Yes' else 'No'" readonly="false()" /> 
     </xforms:model> 
    </xhtml:head> 
    <xhtml:body> 
     <xforms:input ref="instance('instance')/Boolean/@value"> 
     <xforms:label>Boolean: </xforms:label> 
     </xforms:input> 
     <br/> 
     <xforms:output ref="instance('instance')/Boolean"> 
     <xforms:label>Boolean:</xforms:label> 
     </xforms:output> 
     <br/> 
     <xforms:output ref="instance('instance')/Boolean/@value"> 
     <xforms:label>Boolean/@value:</xforms:label> 
     </xforms:output> 
     <br/> 
     <br/> 


    </xhtml:body> 
</xhtml:html> 

ユーザーが上で作業しているときは、ブール値を持っている、あなたのXMLノードに属性を使用することを許可されていない場合形。サブミット・イベントでは、ブール値をYesまたはNoに設定し、データを外部システムにプッシュできます。

+0

はい、追加の属性を使用することはできません。したがって、サブミットイベントでそれらを削除する必要があります。重要な情報は、私自身がブール値を上書きするためにいくつかの魔法属性を使用できる特別な解決策がないことです。 – jaygo