WebObjects/Web 应用程序/开发/示例/路径检查器
外观
首先,对“页面”组件添加一个便捷方法非常实用,这样就可以定义对象的“列表”
protected void addObjectToPathComponents(Object anObject, String aPageName, Object aTitle)
{
if ( anObject != null )
{
Map aMap = new HashMap();
aMap.put( Path.ObjectKey, anObject );
aMap.put( Path.PageNameKey, aPageName );
aMap.put( Path.TitleKey, aTitle );
this.pathComponents().add( aMap );
return;
}
throw new IllegalArgumentException ( "Page.addObjectWithPageNameAndTitleToPath: null object.");
}
现在,你可以在每个具体页面中初始化路径组件
protected void initPathComponents()
{
Envelope anEnvelope = this.value();
Date aDate = anEnvelope.creationDate();
List aList = anEnvelope.list();
this.addObjectToPathComponents( aDate, "Timeline", "TIMELINE" );
this.addObjectToPathComponents( aDate );
if ( aList != null )
{
this.addObjectToPathComponents( aList );
}
this.addObjectToPathComponents( anEnvelope );
}
最后,路径组件本身可以如下所示
<webobject name = "IsMain">
<webobject name = "MainLink"><webobject name = "MainLabel"></webobject></webobject>
</webobject>
<webobject name = "IsNotMain">
<webobject name = "Components">
<webobject name = "HasPrefix"> <webobject name = "Prefix"></webobject> </webobject><webobject name = "Component"></webobject>
</webobject>
<webobject name = "HasPrefix"> <webobject name = "Prefix"></webobject> </webobject><webobject name = "LastComponent"></webobject>
</webobject>
Components: WORepetition
{
count = count;
index = index;
};
IsMain: WOConditional{
condition = isMain;
};
IsNotMain: WOConditional{
condition = isMain;
negate = true;
};
ainLink: WOHyperlink{
action = getMail;
title = "get new mail";
};
MainLabel: SpanString{
value = "get mail";
isSmall = true;
isUpperCase = true;
//isBold = true;
class = "Label";
length = 30;
};
HasPrefix: WOConditional{
condition = hasPrefix;
};
Prefix: WOImage{
src = prefixUrl;
border = 0;
align = "middle";
};
Component: Link{
value = component.object;
description = component.title;
altDescription = component.title;
value = component.object;
pageName = component.pageName;
isUpperCase = true;
isSmall = true;
//isBold = true;
class = "Label";
};
LastComponent: SpanString{
value = lastComponentTitle;
isSmall = true;
isUpperCase = true;
//isBold = true;
class = "Label";
length = 30;
};
就这些了。