Tutorials to .com

Tutorials to .com » Jsp » Tapestry-hivemind » tapestry of research and application of binding

tapestry of research and application of binding

Print View , by: iSee ,Total views: 9 ,Word Count: 1104 ,Date: Thu, 16 Apr 2009 Time: 2:40 AM

,,tapestry(binding),:asset,bean,component,hivemind,listener,literal,message,ognl, state,translator,validator,validators... Introduction: In order to facilitate the configuration, enhanced configuration, tapestry provides a number of binding (binding), such as: asset, bean, component, hivemind, listener, literal, message, ognl, state, translator, validator, validators ...
One of the most commonly used ognl, it is said that behind the ognl expression.

The use of binding, developers can enhance the page / component specification document or template file can be configured in function.

,ImageSubmitimage,IAsset,tapestry,asset,: Question: There is a problem, ImageSubmit components need to set up a property image, its value must be IAsset, tapestry on their practice is to set up a specification document asset, such as:
  <asset name="help" path="images/help.png"/> 
And then applying the asset,
<component id="help" type="ImageSubmit">
<binding name="listener" value="listener:helpSubmit"/>
<binding name="image" value="asset:help"/>
</ component>

,asset。 Note: when invoked, the use of a binding asset.
Is it not too much trouble, is there a simpler way out? After some research I decided to add a binding to get the problem.

contextasset,asset, Improvements: add a contextasset binding, in the following areas need to asset use,
<binding name="image" value="contextasset :/images/help.png"/>
This approach may be more in line with the habits of web developers, you say that?

To achieve:
1, increased binding engineering
public class ContextAssetBindingFactory extends AbstractBindingFactory (
public IBinding createBinding (IComponent root, String bindingDescription, String expression, Location location) (
(bindingDescription,getValueConverter(), location,root,expression); return new ContextAssetBinding (bindingDescription, getValueConverter (), location, root, expression);
)
)

2, increased binding type
public class ContextAssetBinding extends AbstractBinding (

private final IComponent _component;

private final String _path;

protected ContextAssetBinding (String description,
ValueConverter valueConverter, Location location,
IComponent component, String path) (
super (description, valueConverter, location);
this._component = component;
this._path = path;
)

public Object getObject () (

Resource rootResource = this._component.getPage (). GetRequestCycle ()
. getInfrastructure (). getContextRoot ();

String [] paths = _path.split (",");

/ / Only one asset
if (paths.length == 1)
return this.getOneObject (rootResource, _component, _path);
/ / many assets
ContextAsset [] ca = new ContextAsset [paths.length];
for (int i = 0; i <paths.length; i + +) (
ca [i] = null;
)
for (int i = 0; i <paths.length; i + +) (
ca [i] = this.getOneObject (rootResource, _component, paths [i]);
)
return ca;
)

private ContextAsset getOneObject (Resource rootResource,
IComponent component, String path) (
Resource resource = rootResource.getRelativeResource (path);
/ / To support the localization of resources, I would like to thank Sun Bing reminder
resource = resource.getLocalization (component.getPage (). getLocale ());
ContextAsset ca = null;
ca = new ContextAsset (component.getPage (). getRequestCycle ()
. getInfrastructure (). getContextPath (), resource,
new LocationImpl (resource));

if (ca == null)
throw new BindingException (BindingMessages.missingAsset (component,
path), component, getLocation (), this, null);

return ca;
)

)


3, increased allocation of
<! - Add a binding named "ContextAsset Binding"
usage: <binding name="image" value="contextasset:/imgs/login.gif"/>
->
" interface="org.apache.tapestry.binding.BindingFactory"> <service-point id=" ContextAssetBindingFactory "interface="org.apache.tapestry.binding.BindingFactory">
<invoke-factory>
"> <construct class=" mycom.binding.ContextAssetBindingFactory ">
<set-object property="valueConverter" value="infrastructure:valueConverter"/>
</ construct>
</ invoke-factory>
</ service-point>

<contribution configuration-id="tapestry.bindings.BindingFactories">
" service-id=" ContextAssetBindingFactory "/> <binding prefix=" contextasset "service-id=" ContextAssetBindingFactory "/>
</ contribution>

,(CSS),,,Shell,: Summary: [AutoPage] through the simple and practical type of binding, can be easily quoted in component resources (images or CSS), and this binding supports multiple types of resources, including comma-separated, which can also Shell to use components, such as:
<html jwcid="@Shell" stylesheets="contextasset:/css/a.css,/css/b.css" title="test">

You can also type in accordance with this binding, play a valuable your imagination to create a more useful bindings, programmingnot? !


tapestry & hivemind Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.