Tải bản đầy đủ - 0 (trang)
Chapter 4. Creating Complex User Interfaces

Chapter 4. Creating Complex User Interfaces

Tải bản đầy đủ - 0trang

Electronicforms(incontrasttopaperforms)arecharacterized

bytheirabilitytoadapttotheuser'sactionsandgrowas

necessary.Thus,ashoppingapplicationmightstartoffby

displayingashoppingcartwithspaceforasmallnumberof

entries.However,astheuserproceedstoadditemstothe

shoppingcart,theinterfaceadaptsitselfbycreatingadditional

rowsintheshoppingcartinterface.Thisformofdynamismin

XFormsisenabledbyaggregationconstruct repeat described

inSection4.3.

Construct repeat canbenested,andthisabilitycanbeused

toadvantageincreatinguserinterfacesformanipulating

complexhierarchicalstructures.Associatedeventhandlers

insert and delete canbeusedinconjunctionwithrepeating

constructscreatedviaelement repeat toeditandupdate

complexhierarchicalstructuresinteractively.

WeconcludethischapterinSection4.4withastep-by-step

descriptionofacomplexuserinterfacethatusesthevarious

userinterfacecontrolsandaggregationconstructs.



3.8SubmittingData

Theuserinterfacecontrolsdescribedsofarcancollect

userdataandenablethetriggeringofactionsinresponse

touserinteractioneventsandaresufficienttoimplement

alargenumberofonlineinteraction.Whendesigning

XForms,wefeltthatenablingtheusertotriggerthe

specificactionofsubmittingthecollecteddatatotheWeb

serverwassufficientlyimportanttodeserveitsownuser

interfacecontrol.HTML4hadachievedsuchsubmit

buttonsbyoverloadingtheinputcontrolwithavalueof

submitforattributetype.Wedecidedtodefineelement

submit asaseparatesubmitcontrolbecausesubmit

processingissignificantlydifferentfromtheroleplayed

bycontrolsthatallowtheusertoinputdata.

Userinterfacecontrol submit canbeimplemented

usinga trigger controlthatinvokesaction send .In

thissense,element submit issyntacticsugarthatis

presenttoeaseauthoring.

Thissectiondescribescontrol submit andthendetails

submitprocessingasdefinedbyXForms.Aswiththerest

oftheXFormsdesign,submitprocessingreliesonthe

XFormsmodelforencapsulatingallofthedisplayindependentaspectsofsubmitprocessing.SubmissionrelatedinformationisencapsulatedinXFormsmodel

element submission ,whichwillbedescribedinSection

3.8.2.



3.8.1AnatomyofControl submit

Control submit canuseallofthecommonattributes

andelementsdescribedinSection3.2.Control submit ,

like trigger ,doesnotdirectlyaffecttheunderlying

instancedata,andXFormsbindingattributesare

thereforenotrequired.However,asinthecaseof

element trigger ,XFormsbindingattributesmaybe

usedonelement submit toenableordisablethe

submitcontrolconditionally.Inadditiontothesecommon

markupcomponents,requiredattributesubmissionon

element submit isusedtoconnectthesubmitcontrol

withtheportionoftheXFormsmodelthatspecifiesthe

detailsofthedatatobesubmitted.Valueofattribute

submissionspecifiestheidofthecorresponding

submission element.Detailsof



whattosubmit,

wheretosubmit,and

howtosubmit

areencapsulatedinelement submission .

Figure3.27showsanexampleofcontrol submit .When

theuseractivatescontrol submit ,anxforms-submit

eventisdispatchedtoelement submission ,identified

byattributesubmission.



Figure3.27Control submit encapsulatesall

presentationalmetadataassociatedwiththe

submitcontrol.







...









...





Inthisexample,theeventisdispatchtoelement

submission ,identifiedbybuy.Noticethatthisdesign

enablesanXFormsdocumenttocontainmultiple

submissionelements,anadvancedfeaturethatmakes

authoringapplicationscontainingmultipleforms

significantlyeasierthanwhenusingHTMLforms.

Noticefurtherthatthemarkupforelement submit is

completelyindependentofthefinalformrepresentation

usedtorenderthecontrolinagivenmodality.Further,

themarkupdoesnotforcetheauthortospecifytheuser

interactioneventthatshouldtriggerthesubmitaction.

Leavingboththepresentationandinteractionbehaviorof

submitcontrolstobedeterminedbythetargetuser

interactionenvironmentmakestheXFormssubmitcontrol

suitablefordeploymentacrossawidevarietyofend-user

devicesandinteractionmodalities.



3.8.2ModelingWhat,How,andWhereto



Submit

Element submission withinXFormselement model

holdsthenecessarydetailsaboutwhat,where,andhow

tosubmit.NoticethatintheolderHTMLformsdesign,

thisinformationisencapsulatedwithinelement form

thatappearsaspartoftheuserinterfacemarkup.When

designingXForms,theworkinggroupmadeaconscious

decisiontofactoroutallnonpresentationalaspectsof

submitprocessingfromtheuserinteractionmarkup.This

informationiskeptinsidetheXFormsmodelelement

sinceitdoesnotchangewhenbindingdifferent

interactionmodalitiestoagivenXFormsmodel.

Thus,thedatatobecollectedfromtheuser,thelocation

towhichthisdataistransmitted,andthemannerin

whichitisserializedduringtransmissionareall

independentoftheuserinteractionthatwasusedto

collectthedata.Byencapsulatingthisinformationwithin

theXFormsmodel,thisdesignmakesitpossibletobind

eithertheXFormsuserinterfacecontrolsdescribedinthis

chapteroradifferentuserinterfacevocabularytothe

sameunderlyingXFormsmodel.

Inaddition,separatingsubmissiondetailsfromtheuser

interfacecontrolsusedtoinvokethesubmissionhasthe

advantageofenablingasingleXFormsdocumenttooffer

multiplesubmitcontrolswithinthesamedocument,with

eachsubmitcontrolpossiblysubmittingdifferentsubsets

ofthedatacollectedtoadifferentnetworklocation.At

thesametime,thecommonusecaseofsubmittingall

datacollectedfromtheusertoagivenlocationremains

extremelysimple.



3.8.3AnatomyofElement submission

XFormselement model cancontainoneormore

submission elements.Here,wedescribetheattributes

andelementsthatareallowedinelement submission .

Submissionrelatedmetadataiscarriedwithinattributes

onelement submission .Additionally,declarative

XFormseventhandlersmayappearaschildelements

withinelement submission .Sucheventhandlersare

invokedbeforethedataissubmittedandenableauthors

toattachcustombehaviorstoformsubmission.

AsdescribedearlierinSection1.3.4,element

submission specifiesthewhat,how,andwhereofthe

submissionprocess.Attributesofelement submission



aredescribedwithrespecttothefollowingthree

categories:



WhattoSubmit



Binding OptionalXFormsbindingattributes,thatis,

attributepair(model,ref)orattributebind,is

usedtospecifythedatathatistobesubmitted.

Thesebindingattributesareusedtoaddressa

specificportionoftheinstanceifonlyapartof

thedatacollectedistobesubmitted.By

default,thefirstdatainstanceissubmittedin

itsentirety.



WheretoSubmit



action Attributeactionspecifiestheprotocoland

locationfordatasubmission.Thenamewas

chosentoretainconsistencywithHTMLforms

thatuseanactionattributeonelement form

forthesamepurpose.



HowtoSubmit



method Specifiesthemethodusedtosubmitthedata.

Thevalueofthisattributemaybeoneofa

predefinedsetofvaluesdesignedtocover

commonlyusedmethodsontheWebtoday.Itis

alsodesignedtobeextensibletoallowfuture

methods.Thepredefinedvaluesinclude



Method



Description



post



SendXMLusingHTTP

POST



put



SendXMLusingHTTP

PUT



get



HTTPGET



multipart- SendXMLusingHTTP

post

POST

form-data- Senddatausing

post

multipart/form-data

urlencoded- Sendurl-encodeddata

post



Methodnamesnotappearingin

thislistmaybeusedaslongas

theyarequalifiedwiththe

appropriatenamespace.This

providesanextensibility

mechanismforeasily

incorporatingemergingXML

protocols.

separator



Optionalattributeseparator

(defaultis;)specifiesthe

separatorcharacterusedwhen

encodingmultiplefieldsin

conjunctionwithmethodget.This

ispresenttoenableauthorsto

chooseexplicitlybetweenusing&

and;toseparateencodedfields

withinaURLwhenusingmethod

get.TheolderHTMLchoiceof&is

notXML-friendly,andasaresult

Webformsarenowbeginningto

use;astheseparator.This

attributeispresenttogivethe

authorexplicitcontrolif

necessary.



encoding



Attributeencodingspecifiesthe

encodingtousewhenserializing

thedata.



replace



AttributereplaceenablesXForms-



awareuseragentsandserversto

processintelligentlypartial

submissionanddatarefresh.

Whenusingtoday'sHTMLforms,

submittingdatatoaserverresults

intheresponsebeingdeliveredas

anewHTMLpage.Asa

consequence,transactions

consistingofmultiplestages

requireretransmissionofthe

entireWebpagefromserverto

clientateachstageofthe

transaction.

Thiswasnecessitatedbythelack

ofseparationbetweenmodeland

userinteractioninherentinthe

HTMLformsdesign.Givenits

modelvs.interactionseparation,

XFormsprovidesmoredesign

flexibilitywithrespecttohowthe

responsetoaformsubmissionis

processedontheclient.Sincewe

haveseparatedthemodelfrom

theuserinterface,theXForms

authorcanspecifywhethera

submissionresponseistoupdate

oneofeithertheXFormsmodel,

theuserinterface,orbothvia

submissionattributereplace.

XForms1.0specifiesthree

predefinedvaluesforattribute

replace:



Value

all



Description

Serverresponse

replacescurrent

view



instance Serverresponse

replacesonly

instancedata

none



Serverresponse



treatedasan

acknowledgment



Inadditiontothevaluesshown

here,namespacequalifiedvalues

maybeusedforattributereplace

whenexperimentingwithnew

interactionbehaviors.Thedefault

behavioristoreplaceboththe

modelanduserinterfacetomatch

thebehavioroftoday'sHTML

forms.Replacingtheinstance

providesapowerfulmeansof

refreshingtheuserinterface

withoutretransmittingallofthe

originalmarkup.Notethatan

XFormsmodelcancontainmore

thanoneinstance;thisisan

advancedconceptthatis

introducedinalaterchapter.

Whenusingmultipleinstancesin

amodel,XFormsalwaysdefaults

tothefirstinstance,andthisis

trueinthecaseofattribute

replaceaswell.



Themetadataencapsulatedbyelement submission about

howtoserializeinstancedatawasmodeledafterXSLTelement

output .XFormsallowsthefollowingattributestakenfrom

XSLTelement output onelement submission .Theseare

listedseparatelysincetheyareusedlessoftenthanthe

submission attributesdescribedearlier:

indent



Booleanthatspecifiesiftheinstancedatashouldbeindentedwhenitis

serializedasXML



version



SpecifiestheversionofXFormsinuse



omit-xmldeclaration



SpecifiesiftheserializedinstancedatashouldincludethefollowingXML

ProcessingInstruction:







standalone



Specifiesiftheserializedinstancedataisastand-aloneXMLdocument



cdata-section- Nameselementsintheinstancewhosecontentsshouldbeescapedas

elements

XMLCDATAsectionswhenserializingasXML



3.8.4UsingElement submission

Next,wecreateelement submission (seeFigure3.28forthe

markup)neededtocompletetheshoppingcartexample.

Submittingthepurchaseorderbyactivatingcontrol submit

causesthedatastoredin/e-store/carttobeserializedand

transmittedtothelocationspecifiedbyattributeaction.



Figure3.28Element submission thatinitiatesa

buyoperation.

...


action="http://example.com/e-store"method="post"

replace="instance">



Ordering...





TheserverrespondswithanXMLinstancethatholdsupdated

informationabouttheuser'scurrentlyopenordersinsubtree

/e-store/open-orders.Whenthisresponseisreceivedbythe

XFormsclient,thedatamodelisupdated,andanyuser

interfacecontrolsthatbindtoupdatedportionsofthedata

modelarerefreshed.Thus,activatingthebuysubmitcontrol

resultsintheuserinterfacebeingupdatedwithinformation

aboutthenewlyopenedorder.



Assumethattheitemsboughtbytheuserhavebeencollected

intotheXMLsubtreerootedat cart .Noticethatinthis

examplenotallthenodesintheXFormsmodelinstanceareto

besubmittedtotheserver.Thissituationoftenariseswhenan

XFormsapplicationusesaportionofthedatamodeltostore

intermediatecomputedvalues.Suchpartialsubmissionisalso

usefuliftheXFormsauthorhaschosentouseasingle

model/instancepairtostoreallofthedataforanapplication.

Forinstance,theexampleshowninFigure3.29containsfour

XMLsubtreesunderthe e-store rootelement:



Figure3.29Skeletondatamodelusedbya

shoppingapplication.







...

...





...


...







specials Subtreerootedat specials holdsspecialoffers.



scratch Subtreerootedatelement scratch functionsasascratchpadforholding

intermediatevaluesneededbytheshoppingapplication.



cart



Subtreerootedatelement cart holdsoneormore item elements.



open-



Subtreethatholdsinformationabouttheuser'sopenorders.Thissubtreewillbe



orders



usedbytheXFormsserverhostingthee-storeapplicationtoholdinformation

abouttheuser'scurrentlyopenorders.



Inthiscase,weuseanappropriatebindingattribute



ref="/e-store/cart"

onelement submission tolocatethedatathatissubmittedto

theserver.

Attributeactionspecifieswherethedataistobesubmitted.

Attributemethodspecifiesthemethodtouseforserializingand

transmittingthedata.Attributereplaceisusedtospecifyhow

theserverresponseistobeinterpreted.Inthisapplication,the

authorhasspecifiedthattheserverresponsebetreatedasan

updatetotheXFormsdatamodel.

Finally,theauthorhassetupaneventhandlerinsideelement

submission (byusingaction message )thatdisplaysa

messagetotheuserthatthepurchaseorderisbeing

submitted.Eventhandlersinsideelement submission are

invokedbeforethedataistransmittedtothespecifiedlocation.

Thisgivesauthorstheabilitytoaddcustominteractionbehavior

whendataisbeingsubmitted.Notethattoday'sHTMLauthors

dependonscriptingforachievingsimilarfunctionalityby

attachinganeventhandlertotheonsubmitevent.



3.8.5SubmitRound-up

Weconcludethissectionwitharound-upthatsummarizes

submitprocessingfromthetimetheuseractivatescontrol

submit tothefinalstepofupdatingtheuserinterfacebased

ontheserverresponse.Wedescribethisprocessusingevents

andtheactionstheyinvoke.TheXFormsprocessingmodelis



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 4. Creating Complex User Interfaces

Tải bản đầy đủ ngay(0 tr)

×