Das folgende Beispiel zeigt eine typische Postcondition; diese prüft ob der aktuelle Wert (value) dem String „Sonstiges“ entspricht. Im positiven Fall wird für das Formular-Feld „anfallsart_sonst“ dargestellt, ansonsten versteckt.
<dtml-let v="_.str(value)"> <dtml-if "v=='sonstiges'"> <dtml-call "show.append('anfallsart_sonst')"> <dtml-else> <dtml-call "hide.append('anfallsart_sonst')"> </dtml-if> </dtml-let>
Die Auswertung geschieht über den JavaScript-vermittelten Aufruf (AJAX) der serverseitigen Methode validateFormItemPostcondition.xml. Die eingesetzten JavaScript-Funktionen in der Methode formContainer.formulatorSave():
- getValidation(): fordert nach Eingabe eines Formelements per Ajax/JS die Ausführung der Postcondition, indem ein REQUEST an die serverseitige DTML-Methode validateFormItemPostcondition.xml gesendet wird; diese sendet für das aktuelle Formular-Item einen Datenstrom an den Browser zurück, wo dieser per executeValidation() ausgewertet wird
- executeValidation('hints',show=[formItemID,...],hide=[formItemID,...]): liefert für das aktuelle formItem das Darstellungsergebnis zurück. Der String hints schreibt eine Warnung über das Eingabefeld (und erweitert damit den ggf. bestehende hints-Wert). Die beiden Variablen enthalten eine Liste mit Formular-Item-IDs, die entweder explizit gezeigt oder versteckt werden sollen. Hierzu wird per JavaScript das dem Item entsprechende DIV-Element eingefügt.
Die DTML-Methode validateFormItemPostcondition.xml besteht tatsächlich nur aus 3 DTML-Fragmenten, von denen das mittlere die durch den Redakteur erstellte Item-spezifische Postcondition ist. Zwei konstante Code-Elemente (formItem.postconditionPre und formItem.postconditionPost) schachteln die Postcondition, damit daraus ein vollständiger Aufruf werden kann :
- postconditionPre: DTML-Fragment 1 (Konstante)
- postcondition: DTML-Fragment 2 (variabel im Item definiert)
- postconditionPre: DTML-Fragment 3 (Konstante)
<dtml-call "RESPONSE.setHeader('Content-Type','text/xml; charset=utf-8')"> <dtml-call "RESPONSE.setHeader('Content-Disposition','inline;filename=validateFormItemPostcondition.xml')"> <dtml-call "RESPONSE.setHeader('Cache-Control', 'no-cache')"> <dtml-call "RESPONSE.setHeader('Pragma', 'no-cache')"> <dtml-let postcondition="[]"> <dtml-call "postcondition.append(getObjProperty( 'postconditionPre', REQUEST))"> <dtml-call "postcondition.append(getObjAttrValue( getObjAttr('postcondition'), REQUEST))"> <dtml-call "postcondition.append(getObjProperty( 'postconditionPost', REQUEST))"> <dtml-return "dt_html(''.join(postcondition),REQUEST)"> </dtml-let>
<dtml-comment> <!-- ------------- --> <!-- Postconditions --> <!-- ------------- --> </dtml-comment> <dtml-with "getSelf(['formContainer'])"> <dtml-call "getObjProperty('formulatorInit',REQUEST)"> <dtml-call "REQUEST.set('valueOf',{})"> <dtml-in "filteredTreeNodes(REQUEST,['formItem'])"> <dtml-if "REQUEST.form.has_key(id)"> <!-- form.valueOf(<dtml-var "getObjProperty('identifier',REQUEST)">)=<dtml-var "REQUEST.form.get(id)"> --> <dtml-call "REQUEST.set(getObjProperty('identifier',REQUEST),REQUEST.form.get(id))"> <dtml-call "operator_setitem(valueOf,getObjProperty('identifier',REQUEST),REQUEST.form.get(id))"> <dtml-elif "getObjProperty('identifier',REQUEST)"> <!-- valueOf(<dtml-var "getObjProperty('identifier',REQUEST)">)=<dtml-var "editrec.get( getObjProperty('identifier',REQUEST),'')"> --> <dtml-call "REQUEST.set(getObjProperty('identifier',REQUEST), editrec.get( getObjProperty('identifier',REQUEST),''))"> <dtml-call "operator_setitem(valueOf,getObjProperty('identifier',REQUEST),editrec.get( getObjProperty('identifier',REQUEST),''))"> </dtml-if> </dtml-in> </dtml-with> <dtml-let xml="[]"> <dtml-call "REQUEST.set('hints','')"> <dtml-call "REQUEST.set('show',[])"> <dtml-call "REQUEST.set('hide',[])">
<dtml-call "xml.append('<Postcondition')"> <dtml-call "xml.append(' fmname='+QUOT+fmname+QUOT)"> <dtml-call "xml.append(' elname='+QUOT+elname+QUOT)"> <dtml-if hints><dtml-call "xml.append(' hints='+QUOT+hints+QUOT)"></dtml-if> <dtml-call "xml.append('>\n')"> <dtml-in show> <dtml-let item=sequence-item> <dtml-call "xml.append('<show>%s</show>'%item)"> </dtml-let> </dtml-in> <dtml-in hide> <dtml-let item=sequence-item> <dtml-call "xml.append('<hide>%s</hide>'%item)"> </dtml-let> </dtml-in> <dtml-call "xml.append('</Postcondition>\n')"> <dtml-return "getXmlHeader()+''.join(xml)">
</dtml-let>