Class Fragment
- java.lang.Object
-
- org.zkoss.zk.ui.AbstractComponent
-
- org.zkoss.zkmax.zul.Fragment
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Component,DynamicPropertied,Scope,ComponentCtrl
public class Fragment extends AbstractComponent implements DynamicPropertied
A component that let developers combine native HTML elements with ZK data binding syntax to make the static page to be dynamic.@save@load@bind@command@global-command
Usage First, put the HTML source inside the tag and surround them with
<![CDATA[ ]]>. Or you can set thesrcproperty to load an existed file. Then define data as the properties of<fragment>by using@bindonly to map some properties of the view model. In HTML simply bind these data with@save,@loador@bindannotations same as ZK. Notice you cannot bind data with properties of the view model directly, because only these defined at the<fragment>can be accessed in the scope of HTML elements. For example:<fragment viewModel="@id('vm') @init('foo.BarVM')" mydata="@bind(vm.data)"><![CDATA[ <!-- mydata, not vm.data --> <div textContent="@load(mydata)" /> ]]></fragment>textContent attribute for HTML elements This component provides a virtual
textContentattribute for HTML elements to insert data into the tag.<span textContent="@load(foo)"></span>and<span>[foo content]</span>have the same meaning.Shadow Elements This component also provides shadow elements for condition and collection rendering. The usage is nearly the same as ZK Shadow Elements.
<forEach items="" var="" begin="" end="" step="" varStatus=""></forEach><if test=""></if>
Server-side Property/Form Validation You can use
@validatorto validate user input. Remember to initializevalidationMessagesfirst same as ZK. Simply add them with the property binding of<fragment>. Because of the limitation that HTML elements cannot access server side variablevmsgs, you should map the invalid messages too. This component also supports form binding/validation (form="@id('fx') ... @validator"). In this case, you should change the binding prefix from vm (view model) to fx (middle object). For example:<fragment viewModel="@id('vm') @init('foo.BarVM')" validationMessages="@id('vmsgs')" form="@id('fx') @load(vm.currentUser) @save(vm.currentUser, before='submit') @validator('formBeanValidator', prefix='p_')" name="@bind(fx.name)" nameerror="@bind(vmsgs['p_name'])"><![CDATA[ <input type="text" value="@bind(name)"/><span textContent="@load(nameerror)"/> <button onclick="@command('submit')">Submit</button> ]]></fragment>Client-side Property Validation This component also provides a new
@jsvalidator(validation_function_name)syntax to validate at client-side by evaluating your custom JavaScript function. It can be used inside the HTML source code only and cannot be used separately without data binding. Just like ZK, it provides a validation message holder (vmsgs) implicitly for displaying error. The differences are you don't need to initializevalidationMessagesand you are responsible for cleaning the invalid message if it is valid. For example:<fragment viewModel="@id('vm') @init('foo.BarVM')" someprop="@bind(vm.prop1)"><![CDATA[ <input type="text" value="@bind(someprop) @jsvalidator('validateExample')"/> <span textContent="@load(vmsgs['foo'])"/> <script type="text/javascript"> // @param val The value of user input // @param vmsgs A object of validation message holder // @return boolean true if it is valid function validateExample(val, vmsgs) { var isValid = someValidationProcess(val); vmsgs['foo'] = isValid ? '' : 'Invalid value'; return isValid; } </script> ]]></fragment>Note: This component can only support those browsers which support ECMAScript 5. Like IE9+, Firefox, Safari, Opera, and Chrome.
- Since:
- 8.5.0
- Author:
- wenninghsu, rudyhuang
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
AbstractComponent.Children, AbstractComponent.ForwardInfo, AbstractComponent.TargetInfo
-
-
Field Summary
-
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
-
Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
-
-
Constructor Summary
Constructors Constructor Description Fragment()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>getCmdArgs()Internal Use Onlyjava.util.Map<java.lang.String,java.lang.Object>getDynamicProperties()Returns all available dynamic properties.java.lang.ObjectgetDynamicProperty(java.lang.String name)Returns the property value of the specified name.booleanhasDynamicProperty(java.lang.String name)Returns whether a dynamic property is defined.protected voidrenderProperties(ContentRenderer renderer)Called by (ComponentCtrl.redraw(java.io.Writer)) to render the properties, excluding the enclosing tag and children.voidservice(AuRequest request, boolean everError)Handles an AU request.voidsetContent(java.lang.String content)Sets the content of this component.voidsetDynamicProperty(java.lang.String name, java.lang.Object value)Sets a property with the specified name and value.voidsetRecoverId(java.lang.String recoverId)Sets the recover ID.voidsetSrc(java.lang.String src)Sets the URI of an external content file.-
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, clone, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getExtraCtrl, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getPropertyAccess, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isChildable, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
-
-
-
Method Detail
-
setSrc
public void setSrc(java.lang.String src)
Sets the URI of an external content file. The file encoding is assumed to be UTF-8.- Parameters:
src- the URI of an external content file- See Also:
setContent(java.lang.String)
-
getCmdArgs
public java.util.Map<java.lang.String,java.lang.Object> getCmdArgs()
Internal Use Only
-
setContent
public void setContent(java.lang.String content)
Sets the content of this component.- Parameters:
content- the content of this component- See Also:
setSrc(java.lang.String)
-
setRecoverId
public void setRecoverId(java.lang.String recoverId)
Sets the recover ID.- Parameters:
recoverId- An identifier
-
renderProperties
protected void renderProperties(ContentRenderer renderer) throws java.io.IOException
Description copied from class:AbstractComponentCalled by (ComponentCtrl.redraw(java.io.Writer)) to render the properties, excluding the enclosing tag and children.Default: it renders
AbstractComponent.getId()if it was assigned, and event names if listened (and listed inAbstractComponent.getClientEvents()).Note: it doesn't render
AbstractComponent.getWidgetClass(),AbstractComponent.getUuid()andAbstractComponent.getMold(), which are caller's job.- Overrides:
renderPropertiesin classAbstractComponent- Throws:
java.io.IOException
-
service
public void service(AuRequest request, boolean everError)
Description copied from class:AbstractComponentHandles an AU request. It is invoked internally.Default: it handles echo and setAttr, and it converts other request to an event (by
Event.getEvent(org.zkoss.zk.au.AuRequest)) and then posts the event (byEvents.postEvent(org.zkoss.zk.ui.event.Event)).Application developer can plug the custom service to handle the AU request by
AbstractComponent.setAuService(org.zkoss.zk.au.AuService).- Specified by:
servicein interfaceComponentCtrl- Overrides:
servicein classAbstractComponenteverError- whether any error ever occurred before processing this request.- See Also:
AbstractComponent.setAuService(org.zkoss.zk.au.AuService)
-
hasDynamicProperty
public boolean hasDynamicProperty(java.lang.String name)
Description copied from interface:DynamicPropertiedReturns whether a dynamic property is defined.- Specified by:
hasDynamicPropertyin interfaceDynamicPropertied
-
getDynamicProperties
public java.util.Map<java.lang.String,java.lang.Object> getDynamicProperties()
Description copied from interface:DynamicPropertiedReturns all available dynamic properties.- Specified by:
getDynamicPropertiesin interfaceDynamicPropertied
-
getDynamicProperty
public java.lang.Object getDynamicProperty(java.lang.String name)
Description copied from interface:DynamicPropertiedReturns the property value of the specified name.- Specified by:
getDynamicPropertyin interfaceDynamicPropertied
-
setDynamicProperty
public void setDynamicProperty(java.lang.String name, java.lang.Object value) throws WrongValueExceptionDescription copied from interface:DynamicPropertiedSets a property with the specified name and value.If a component supports only String-type values, it could use org.zkoss.lang.Objects.toString() to convert the value to a String instance.
- Specified by:
setDynamicPropertyin interfaceDynamicPropertied- Throws:
WrongValueException
-
-