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 thesrc
property to load an existed file. Then define data as the properties of<fragment>
by using@bind
only to map some properties of the view model. In HTML simply bind these data with@save
,@load
or@bind
annotations 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
textContent
attribute 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
@validator
to validate user input. Remember to initializevalidationMessages
first 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 initializevalidationMessages
and 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.Object
getDynamicProperty(java.lang.String name)
Returns the property value of the specified name.boolean
hasDynamicProperty(java.lang.String name)
Returns whether a dynamic property is defined.protected void
renderProperties(ContentRenderer renderer)
Called by (ComponentCtrl.redraw(java.io.Writer)
) to render the properties, excluding the enclosing tag and children.void
service(AuRequest request, boolean everError)
Handles an AU request.void
setContent(java.lang.String content)
Sets the content of this component.void
setDynamicProperty(java.lang.String name, java.lang.Object value)
Sets a property with the specified name and value.void
setRecoverId(java.lang.String recoverId)
Sets the recover ID.void
setSrc(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:AbstractComponent
Called 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:
renderProperties
in classAbstractComponent
- Throws:
java.io.IOException
-
service
public void service(AuRequest request, boolean everError)
Description copied from class:AbstractComponent
Handles 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:
service
in interfaceComponentCtrl
- Overrides:
service
in classAbstractComponent
everError
- 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:DynamicPropertied
Returns whether a dynamic property is defined.- Specified by:
hasDynamicProperty
in interfaceDynamicPropertied
-
getDynamicProperties
public java.util.Map<java.lang.String,java.lang.Object> getDynamicProperties()
Description copied from interface:DynamicPropertied
Returns all available dynamic properties.- Specified by:
getDynamicProperties
in interfaceDynamicPropertied
-
getDynamicProperty
public java.lang.Object getDynamicProperty(java.lang.String name)
Description copied from interface:DynamicPropertied
Returns the property value of the specified name.- Specified by:
getDynamicProperty
in interfaceDynamicPropertied
-
setDynamicProperty
public void setDynamicProperty(java.lang.String name, java.lang.Object value) throws WrongValueException
Description copied from interface:DynamicPropertied
Sets 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:
setDynamicProperty
in interfaceDynamicPropertied
- Throws:
WrongValueException
-
-