[Xsltforms-support] selection of default value in select1
Brought to you by:
alain-couthures
From: Stephen C. <Ste...@ut...> - 2009-11-30 02:40:01
|
The xform below contains my solution to selection of default values in select1 lists, note the 'set-selected' custom action that gets fired by the 'xforms-ready' event. This is working in firefox but there are some problems in IE that will probably be fixed by upgrading to a newer version of xsltforms. Constructive criticism welcomed. Note that I am using a Web Feature Service (WFS) as my backend data source/sink. <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?> <html xmlns:aatams="http://www.imos.org.au/aatams" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns="http://www.w3.org/1999/xhtml" xmlns:gml="http://www.opengis.net/gml"> <head> <title>AATAMS Web Interface</title> <link href="aatams.css" rel="stylesheet" type="text/css" /> <xf:model id="model1"> <xf:instance id="inst_data"> <wfs:Transaction version="1.1.0" service="WFS"> <wfs:Insert> <wfs:FeatureCollection> <gml:featureMember> <aatams:device> <aatams:code_name /> <aatams:device_type_ref> <aatams:device_type> <aatams:name> RECEIVER </aatams:name> </aatams:device_type> </aatams:device_type_ref> <aatams:device_model_ref> <aatams:device_model /> </aatams:device_model_ref> <aatams:serial_number /> <aatams:project_person_ref> <aatams:project_person /> </aatams:project_person_ref> </aatams:device> </gml:featureMember> </wfs:FeatureCollection> </wfs:Insert> </wfs:Transaction> </xf:instance> <xf:instance id="inst_subfeatures"> <data xmlns=""> <device_model_id /> <device_type_id /> <project_id /> <project_person_id /> </data> </xf:instance> <xf:instance id="inst_device_model" src="../../deegree-wfs/services?service=WFS&version=1.1.0&request=GetFeature&namespace=xmlns(aatams=http://www.imos.org.au/aatams)&typename=aatams:device_model&filter=<ogc:Filter xmlns:ogc='http://www.opengis.net/ogc' xmlns:aatams='http://www.imos.org.au/aatams' xmlns:gml='http://www.opengis.net/gml'><ogc:PropertyIsEqualTo><ogc:PropertyName>aatams:device_type_ref/aatams:device_type/aatams:name</ogc:PropertyName><ogc:Literal>RECEIVER</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>" /> <xf:instance id="inst_project_person" src="../../deegree-wfs/services?service=WFS&version=1.1.0&request=GetFeature&namespace=xmlns(aatams=http://www.imos.org.au/aatams)&typename=aatams:project_person" /> <xf:instance id="inst_project" src="../../deegree-wfs/services?service=WFS&version=1.1.0&request=GetFeature&namespace=xmlns(aatams=http://www.imos.org.au/aatams)&typename=aatams:project" /> <xf:instance id="inst_response"> <dummy xmlns=""> <ows:Exception /> <wfs:TransactionResponse> <wfs:InsertResults> <wfs:Feature> <ogc:FeatureId /> </wfs:Feature> </wfs:InsertResults> </wfs:TransactionResponse> </dummy> </xf:instance> <xf:bind id="code_name" nodeset="instance('inst_data')//aatams:code_name" type="xsd:string" required="true()" /> <xf:bind id="device_model" nodeset="instance('inst_subfeatures')//device_model_id" type="xsd:string" required="true()" /> <xf:bind id="serial_number" nodeset="instance('inst_data')//aatams:serial_number" type="xsd:string" required="true()" /> <xf:bind id="project" nodeset="instance('inst_subfeatures')//project_id" type="xsd:string" required="true()" /> <xf:bind id="project_person" nodeset="instance('inst_subfeatures')//project_person_id" type="xsd:string" required="true()" /> <xf:bind id="error_message" nodeset="instance('inst_response')//ServiceException" type="xsd:string" /> <xf:bind id="success_message" nodeset="instance('inst_response')//ogc:FeatureId/@fid" type="xsd:string" /> <xf:submission id="s01" ref="instance('inst_data')" method="post" action="../../deegree-wfs/services" replace="instance" instance="inst_response"> <xf:action ev:event="xforms-submit"> <xf:delete nodeset="instance('inst_data')//aatams:status_id[.='']" /> <xf:insert nodeset="instance('inst_data')//aatams:device_model_ref/aatams:device_model" origin="instance('inst_device_model')//aatams:device_model[@gml:id=instance('inst_subfeatures')/device_model_id]" /> <xf:delete nodeset="instance('inst_data')//aatams:device_model_ref/aatams:device_model" at="1" /> <xf:insert nodeset="instance('inst_data')//aatams:project_person_ref/aatams:project_person" origin="instance('inst_project_person')//aatams:project_person[@gml:id=instance('inst_subfeatures')/project_person_id]" /> <xf:delete nodeset="instance('inst_data')//aatams:project_person_ref/aatams:project_person" at="1" /> </xf:action> <xf:message level="modeless" ev:event="xforms-submit-error"> Submit error. </xf:message> </xf:submission> <xf:dispatch ev:event="xforms-ready" name="set-selected" target="model1" /> <xf:action ev:event="set-selected"> <xf:setvalue ref="instance('inst_subfeatures')//device_model_id" value="instance('inst_device_model')//aatams:device_model[1]/@gml:id" /> <xf:setvalue ref="instance('inst_subfeatures')//project_id" value="instance('inst_project')//aatams:project[1]/@gml:id" /> <xf:setvalue ref="instance('inst_subfeatures')//project_person_id" value="instance('inst_project_person')//aatams:project_person[aatams:project_fid=instance('inst_subfeatures')/project_id][1]/@gml:id" /> <xf:dispatch name="xforms-revalidate" target="model1" /> </xf:action> </xf:model> </head> <body><!--Debug--> <div class="form"> <legend>ADD RECEIVER DEVICE</legend> <div class="form-contents"> <xf:input bind="code_name" incremental="true()"> <xf:label>Code Name</xf:label> </xf:input> <!-- xf:select1 bind="device_type" appearance="minimal" incremental="true()"> <xf:label>Device Type</xf:label> <xf:itemset nodeset="instance('inst_device_type')//aatams:device_type"> <xf:value ref="@gml:id"/> <xf:label ref="aatams:name"/> </xf:itemset> </xf:select1--> <xf:select1 bind="device_model" appearance="minimal" incremental="true()"> <xf:label>Model</xf:label> <xf:itemset nodeset="instance('inst_device_model')//aatams:device_model"> <xf:value ref="@gml:id" /> <xf:label ref="aatams:name" /> </xf:itemset> </xf:select1> <xf:input bind="serial_number" incremental="true()"> <xf:label>Serial Number</xf:label> </xf:input> <div class="dependant-selects"> <xf:select1 bind="project" appearance="minimal" incremental="true()"> <xf:label>Project</xf:label> <xf:itemset nodeset="instance('inst_project')//aatams:project"> <xf:value ref="@gml:id" /> <xf:label ref="aatams:name" /> </xf:itemset> <xf:action ev:event="xforms-value-changed"> <xf:setvalue ref="instance('inst_subfeatures')//project_person_id" value="" /> </xf:action> </xf:select1> <xf:select1 bind="project_person" appearance="minimal" incremental="true()"> <xf:label>Person(Role)</xf:label> <xf:itemset nodeset="instance('inst_project_person')//aatams:project_person[aatams:project_fid=instance('inst_subfeatures')/project_id]"> <xf:value ref="@gml:id" /> <xf:label ref="aatams:person_role" /> </xf:itemset> </xf:select1> </div> <xf:submit submission="s01"> <xf:label>Save</xf:label> </xf:submit> <xf:trigger> <xf:label>Reset</xf:label> <xf:reset ev:event="DOMActivate" /> <xf:dispatch ev:event="DOMActivate" name="set-selected" target="model1" /> <xf:delete ev:event="DOMActivate" nodeset="instance('inst_response')//ServiceException" /> <xf:delete ev:event="DOMActivate" nodeset="instance('inst_response')//ogc:FeatureId/@fid" /> </xf:trigger> <xf:group> <xf:output bind="error_message" class="error"> <xf:label>Error:</xf:label> </xf:output> <xf:output bind="success_message"> <xf:label>New Record Id:</xf:label> </xf:output> </xf:group> </div> </div> <br /> <div id="console" /> </body> </html> -- Regards Stephen Cameron Data Programmer Integrated Marine Observing System (IMOS) eMarine Information Infrastructure Project University of Tasmania, Private Bag 21, Hobart, TAS 7001, Australia Tel: +61 3 6226 8507 Fax: +61 3 6226 2997 Email: ste...@ut... URL: http://www.imos.org.au/eMII.html |