Hi Stephen
Thanks for your description of ATG's switch tags.
> I agree, it would be nice to define blocks of jsp code that could be
> executed on demand. ATG's Dynamo page programming language has a
> feature called "oparams" that allow one to do just that.
I agree that calling "on demand" can be simulated (inefficiently) via
evaluating the whole of the Switch tag body and initialising & evaluating
all of the Case / DefauiltCase tags in turn and each of the each of them
deciding if they should evaluate their body by negotiating with their
parent.
It is analagous to implementing a Map/Hashtable lookup by brute force, doing
an if statement for *every* key in the Map. It works but is not the optimal
solution. (In fact it is harder to be more inefficent ;-)
> Then, when the doStartTag of
> the foo:Case tag executes, it first checks to see if childOfSwitchTag is
> true. If it is, it then checks the to see if the value of its switchTag
> property's doneTesting property is set to false. If it is false, then the
> "value" attribute of the parent foo:Switch tag is compared with the
> "value" attribute of the foo:Case tag. If they are equal, then the
> doStartTag sets the doneTesting property of the parent foo:Switch tag to
> true, returns EVAL_BODY_INCLUDE and renders the body of the foo:Case
> tag. If the doneTesting property is true, or the foo:Case tag's "value"
> property does not equal the "value" property of the parent foo:Switch,
> then the doStartTag returns SKIP_BODY, and the doneTesting property of the
> parent foo:Switch tag is not modified.
Thats alot of work to do for each value in a switch statement, especially if
the switch occurs inside a large loop. It could be as efficient as the code
in the doEndTag() method below if we had something like "RunnableTags" :-
public class SwitchTag extends TagSupport {
private Object value;
private Map caseMap = new HashMap();
private RunnableTag defaultCaseTag;
public int doEndTag() {
CaseTag caseTag = (CaseTag) caseMap.get( value );
if ( caseTag != null ) {
caseTag.run();
}
else
defaultCaseTag.run();
}
return EVAL_PAGE;
}
public void setValue( Object value ) {
this.value = value;
}
public void addCaseTag( Object caseValue, RunnableTag caseTag ) {
caseMap.put( caseValue, caseTag );
}
pubic void setDefaultCaseTag( RunnableTag defaultCaseTag ) {
this.defaultCaseTag = defaultCaseTag;
}
}
> Here is an example of these three tags in action:
I liked your example ;-)
> I know this doesn't solve the problem of rendering jsp blocks on
> demand, but it does try to minimize the performance loss of the
> "conventional" approach.
Agreed.
<James/>
James Strachan
=============
email: [EMAIL PROTECTED]
web: http://www.metastuff.com
__________________________________________________________________
If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited.
Views expressed are those of the author and do not necessarily
represent those of Citria Limited.
__________________________________________________________________