XForms Tutorial > I-1.3.4. bind element
XForms Model 하위 요소로 구성되어 있는 Bind 엘리먼트는 nodeset attribute의 Model Binding Expression을 통해 인스턴스 노드를 선택하며, 모델 아이템 프로퍼티 어트리뷰트를 통해 각 노드에 그 속성들을 적용하게 된다.
인스턴스 노드를 선택할 수 있는 바인딩 어트리뷰트에는 ref와 bind가 있다. bind 어트리뷰트는 Bind 엘리먼트를 참조하는 어트리뷰트이며, XForms Control 뿐만 아니라 Submission 엘리먼트 등에서 다양하게 사용된다. 바인딩을 위한 어트리뷰트에는 노드를 직접적으로 가리키는 ref와 Bind 엘리먼트를 통해 노드를 선택하는 bind가 있다. 이 두 가지 방법 중 XForms는 bind 어트리뷰트를 권장하고 있다.
Common Attributes
- Common, Model Item Properties
- nodeset : nodes 의 set을 선택하는 Model Binding Expression 이다.(Model Binding Expressions 참조)
Making a connection – Binding Model Item Properties와 instance data node를 연결하는 것이 Binding이다. bind는 두 끝점이 있는데 한 쪽은 XForms Model이고, 다른 쪽은 Form Control이다. XForms Model내의 bind element에서는 nodeset attribute가 Model Binding Expression을 확보하고, User Interface에서는 UI Binding Expression이 된다. 이 두 끝점은 IDREF나 XPath를 사용하여 bind된다.
with IDREFs 각 Form Control에 bind attribute가 IDREF를 넘겨서, 각 bind element에 id attribute를 두고 Binding을 수행하는 방법이다
<!-- in the XForms Model --> <xforms:bind nodeset="email" id="mybind" required="true()"/> ... <!-- later in the document --> <xforms:input bind="mybind"...>
with XPath Form Control에서 ref attribute의 XPath Expression 을 사용하여 instance data node에 직접 Binding 하는 방법이다.
<!-- in the XForms Model --> <xforms:bind nodeset="email" id="mybind" required="true( )"/> ... <!-- later in the document --> <xforms:input ref="email"...>
Multiple Model 동일한 Document 내에 여러 Form이 있는 것은 일반적이다. 이러한 경우 Multiple XForms Model을 갖는다.
<!-- in the XForms Model 1 --> <xform:model id="m1"> <xforms:bind nodeset="email" type="my:email"/> ... </xforms:model> <xforms:model id="m2"> <xforms:bind nodeset="search" type="my:query"/> ... </xforms:model> <!-- later in the document --> <xforms:input ref="email" model="m1"...> <xforms:input ref="search" model="m2"...>
Multiple Instance HTML Form의 Hidden Field처럼 계산등을 위한 추가적인 데이터가 Form에 필요할 수 있다. 그러나, XForms 에서는 Initial Form Data가 광범위하게 배치된 XML이다. 종종 지금 있는 DTD와 XML Schema를 수정할 수 없을 때가 있다. 이럴 경우에 임시 스토리지로 XForms Instance를 추가할 수 있다.
<!-- in the XForms Model -->
<xforms:model>
<xforms:instance id="formdata">
<my:root>
...
</my:root>
</xforms:instance>
<xforms:instance id="userid" src="scripts/getuserid"/>
...
<xforms:bind nodeset="my:root/..."/>
<xforms:bind nodeset="instance('userid')/..."/>
...
</xforms:model>...(생략)...
<xforms:model id="form1">
<xforms:instance id="instance1">
<instanceData>
<p1>1</p1>
<p2>2</p2>
<p3>3</p3>
</instanceData>
</xforms:instance>
<xforms:instance id="instance2">
<instanceData>
<p4>4</p4>
<p5>5</p5>
<p6>6</p6>
</instanceData>
</xforms:instance>
<xforms:bind nodeset="instance('instance2')" id="conn2" />
<xforms:bind nodeset="instance('instance1')" id="conn1" />
<xforms:submission id="submit01" method="post"
action="http://xformstest.org/cgi-bin/echo.sh" indent="1" bind="conn1"/>
</xforms:model>
... (생략)...
댓글 없음:
댓글 쓰기