RE: [FreeMarker-user] FW: crud screens and null.
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
|
From: Payne, M. <Pay...@pe...> - 2006-05-02 15:10:24
|
Re:=20
You can use (really.long.property.chain)?default("...") - note the =20
parentheses around the property chain - to fall back to a default when =20
*any* part of the property chain is missing, not only the last =
component.
Didn't know that could be used against a whole chain.
e.g.=20
${(really.long.property.chain)?default("...")}
That may help, thanks for your help and samples. Its not looking as bad =
as I thought.
-Matt
-----Original Message-----
From: fre...@li... =
[mailto:fre...@li...] On Behalf Of =
Attila Szegedi
Sent: Tuesday, May 02, 2006 10:41 AM
To: fre...@li...
Subject: Re: [FreeMarker-user] FW: crud screens and null.
On Mon, 01 May 2006 22:58:39 +0200, Payne, Matthew =20
<Pay...@pe...> wrote:
>
> Does freemarker support a "!" notation?
> .default("") is not quite the same thing if the property or its parent =
=20
> object does not exist, but its okay.
You can use (really.long.property.chain)?default("...") - note the =20
parentheses around the property chain - to fall back to a default when =20
*any* part of the property chain is missing, not only the last =
component.
You can also enclose your template (at least in that "edit" mode) with
<#escape x as (x)?default("...")>
...
</#escape>
and have each expression "expr" occurring inside ${} (that is, ${expr}) =
be =20
transformed into ${(expr)?default("...")} inside the <#escape> block.
Oh, and as an alternative to all of that, you can create a nice little =20
model for your "edit" and "preview" views that'll actually cause the =20
template to print all expressions - just toss an object of the class =
below =20
as a root model in your template.process():
-------------------------------------------------------------
public class FakeModel
implements TemplateScalarModel, TemplateBooleanModel,
TemplateHashModel, TemplateSequenceModel, TemplateMethodModel
{
private final String text;
public FakeModel()
{
this("");
}
public FakeModel(String text)
{
this.text =3D text;
}
public String getAsString()
{
return "${" + text + "}";
}
public boolean getAsBoolean()
{
return true;
}
public TemplateModel get(String key)
{
return new FakeModel(text + "." + key);
}
public TemplateModel get(int index)
{
return new FakeModel(text + "[" + index + "]");
}
public boolean isEmpty()
{
return false;
}
public int size()
{
return 1;
}
public TemplateModel exec(List args) throws TemplateModelException
{
return new FakeModel(text + args.toString().replace('[', =20
'(').replace(']', ')'));
}
}
-------------------------------------------------------------
Cheers,
Attila.
--=20
home: http://www.szegedi.org
weblog: http://constc.blogspot.com
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, =
security?
Get stuff done quickly with pre-integrated technology to make your job =
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache =
Geronimo
http://sel.as-us.falkag.net/sel?cmd=3Dk&kid=120709&bid&3057&dat=121642
_______________________________________________
FreeMarker-user mailing list
Fre...@li...
https://lists.sourceforge.net/lists/listinfo/freemarker-user
This message, including any attachments, is intended only for the recipie=
nt(s) =
named above. It may contain confidential and privileged information. If y=
ou have =
received this communication in error, please notify the sender immediatel=
y and =
destroy or delete the original message. Also, please be aware that if you=
are not =
the intended recipient, any review, disclosure, copying, distribution or =
any =
action or reliance based on this message is prohibited by law. =
=0D
|