public class Fragment extends AbstractComponent implements DynamicPropertied
@save
@load
@bind
@command
@global-command
Usage
First, put the HTML source inside the tag and surround them with <![CDATA[ ]]>
.
Or you can set the src
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 initialize validationMessages
first same as ZK.
Simply add them with the property binding of <fragment>
.
Because of the limitation that HTML elements cannot access server side variable
vmsgs
, 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 initialize validationMessages
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.
AbstractComponent.Children
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
Constructor and Description |
---|
Fragment() |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
getCmdArgs()
Internal Use Only
|
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.
|
addAnnotation, addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, clone, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, enableBindingAnnotation, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, 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, getId, getLastChild, getListenerIterator, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getPropertyAccess, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttribute, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, insertBefore, invalidate, isChildable, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, 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, setWidgetAttribute, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
public void setSrc(java.lang.String src)
src
- the URI of an external content filesetContent(java.lang.String)
public java.util.Map<java.lang.String,java.lang.Object> getCmdArgs()
public void setContent(java.lang.String content)
content
- the content of this componentsetSrc(java.lang.String)
public void setRecoverId(java.lang.String recoverId)
recoverId
- An identifierprotected void renderProperties(ContentRenderer renderer) throws java.io.IOException
AbstractComponent
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 in AbstractComponent.getClientEvents()
).
Note: it doesn't render AbstractComponent.getWidgetClass()
, AbstractComponent.getUuid()
and AbstractComponent.getMold()
, which are caller's job.
renderProperties
in class AbstractComponent
java.io.IOException
public void service(AuRequest request, boolean everError)
AbstractComponent
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
(by Events.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)
.
service
in interface ComponentCtrl
service
in class AbstractComponent
everError
- whether any error ever occurred before
processing this request.AbstractComponent.setAuService(org.zkoss.zk.au.AuService)
public boolean hasDynamicProperty(java.lang.String name)
DynamicPropertied
hasDynamicProperty
in interface DynamicPropertied
public java.lang.Object getDynamicProperty(java.lang.String name)
DynamicPropertied
getDynamicProperty
in interface DynamicPropertied
public void setDynamicProperty(java.lang.String name, java.lang.Object value) throws WrongValueException
DynamicPropertied
If a component supports only String-type values, it could use org.zkoss.lang.Objects.toString() to convert the value to a String instance.
setDynamicProperty
in interface DynamicPropertied
WrongValueException
Copyright © 2005-2018 Potix Corporation. All Rights Reserved.