You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Lewis <ch...@bellsouth.net> on 2008/01/07 20:07:43 UTC

T5: var: in 5.0.8

I like the new var: prefix for temp variables, although I can't find any 
docs on how to properly use it. Here's my template code:

<div t:type="layouts/General" title="e" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    <div t:type="loop" source="recentPosts" value="var:post">
        <div>${var:post}</div>
        <div>${var:post.title}</div>
        <div>${var:post.body}</div>
        <div>${var:post.created}</div>
    </div>
</div>


When I run this I get an exception:

"Component blog/Start does not contain a stored render variable with 
name 'post.title'. Stored render variables: post."

So it sees my stored render variable, but thinks post.something 
represents a different property. Having just read the issue at 
https://issues.apache.org/jira/browse/TAPESTRY-1830 it seems that only 
simple objects (probably ending in a toString call?) are supported. Is 
that true, and if so, is that the extent of what will be done? I haven't 
dug in to the code, but couldn't you infer the type based on the type of 
the collection supplied to the source parameter?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: var: in 5.0.8

Posted by Howard Lewis Ship <hl...@gmail.com>.
Check the nightly build for latest documentation.  This is covered.

var: is decidedly simple, you can reference a render variable, but
since it is an Object in a Map, Tapestry doesn't have any type
information about the Object, to allow it to build (non-reflective)
property access, the way prop: does.  So you can use var: when
- You need to transfer a value from one component to another (or to an
expansion)
- You don't need to access properties inside the value
- You don't want to define a real property (instance variable, getter
and setter)

It is purposely minimal, to avoid abuse.  It's kind of handy for
outputting lists:

<ul>
<li t:type="loop" source="myItems" value="var:item">${var:item}</li>
</ul>

But anything much more complicated requires the prop: binding prefix
and a real property.

On Jan 7, 2008 12:23 PM, Davor Hrg <hr...@gmail.com> wrote:
> var: is for simple usages only,
> var: is not a prefix like prop: it will not generate an expression
>
> extracting type from combined binding is i a tedious job and probably
> not even possible do be done right:
>
>  <div t:type="loop" source="recentPosts" value="var:post">
>
> tapestry would have to know somehow about the connection between
> recentPosts and var:post
>
> loop is just a component... how is T5 supposed to know that elements from
> recentPosts are to be stored into var:post....
>
>
>
> use page properties, this way tapestry can compile expressions in advance...
>
> private Post post;
>
> ..getPost()
> ..setPost()
>
> if you don't want getters and setters "cluttering" your code , someone
> on the list
> has a solution that can add them on the fly via annotation....
>
>
> hope I'm making sense...
>
> Davor Hrg
>
>
> On Jan 7, 2008 8:07 PM, Chris Lewis <ch...@bellsouth.net> wrote:
> > I like the new var: prefix for temp variables, although I can't find any
> > docs on how to properly use it. Here's my template code:
> >
> > <div t:type="layouts/General" title="e"
> > xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> >     <div t:type="loop" source="recentPosts" value="var:post">
> >         <div>${var:post}</div>
> >         <div>${var:post.title}</div>
> >         <div>${var:post.body}</div>
> >         <div>${var:post.created}</div>
> >     </div>
> > </div>
> >
> >
> > When I run this I get an exception:
> >
> > "Component blog/Start does not contain a stored render variable with
> > name 'post.title'. Stored render variables: post."
> >
> > So it sees my stored render variable, but thinks post.something
> > represents a different property. Having just read the issue at
> > https://issues.apache.org/jira/browse/TAPESTRY-1830 it seems that only
> > simple objects (probably ending in a toString call?) are supported. Is
> > that true, and if so, is that the extent of what will be done? I haven't
> > dug in to the code, but couldn't you infer the type based on the type of
> > the collection supplied to the source parameter?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: var: in 5.0.8

Posted by Kevin Menard <km...@servprise.com>.
On 1/7/08 3:23 PM, in article
84d1dff00801071223u71fa87dbgcfb85cc73b82bd73@mail.gmail.com, "Davor Hrg"
<hr...@gmail.com> wrote:

> var: is for simple usages only,
> var: is not a prefix like prop: it will not generate an expression
> 
> extracting type from combined binding is i a tedious job and probably
> not even possible do be done right:

Unless I'm mistaken, OGNL did an okay job with it in T4.

> 
>  <div t:type="loop" source="recentPosts" value="var:post">
> 
> tapestry would have to know somehow about the connection between
> recentPosts and var:post
> 
> loop is just a component... how is T5 supposed to know that elements from
> recentPosts are to be stored into var:post....

Runtime reflection is doable on an Object reference.  Much slower, granted,
and certainly not what var or prop is designed to handle.

I see the current var work as a stepping stone for more complicated work
down the line.


> use page properties, this way tapestry can compile expressions in advance...
> 
> private Post post;
> 
> ..getPost()
> 
> ..setPost()
> 
> 
> if you don't want getters and setters "cluttering" your code , someone
> on the list
> has a solution that can add them on the fly via annotation....

The issue isn't so much one of clutter as it is one of static analysis.  If
the only reason the property exists is as a temporary holder for a
component, why bother adding it to the page class?  The code will never be
called from within the page or anywhere other than within Tapestry.  How do
you adequately deal with code rot in such an environment?

The annotation, which does cut out the getter/setter portion, still requires
the addition of an unused property to the class.  What I do like about the
annotation, however, is that it does imbue semantic meaning, so at least I
know where to look for usages when cleaning up code.

-- 
Kevin



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: var: in 5.0.8

Posted by Davor Hrg <hr...@gmail.com>.
var: is for simple usages only,
var: is not a prefix like prop: it will not generate an expression

extracting type from combined binding is i a tedious job and probably
not even possible do be done right:

 <div t:type="loop" source="recentPosts" value="var:post">

tapestry would have to know somehow about the connection between
recentPosts and var:post

loop is just a component... how is T5 supposed to know that elements from
recentPosts are to be stored into var:post....



use page properties, this way tapestry can compile expressions in advance...

private Post post;

..getPost()
..setPost()

if you don't want getters and setters "cluttering" your code , someone
on the list
has a solution that can add them on the fly via annotation....


hope I'm making sense...

Davor Hrg

On Jan 7, 2008 8:07 PM, Chris Lewis <ch...@bellsouth.net> wrote:
> I like the new var: prefix for temp variables, although I can't find any
> docs on how to properly use it. Here's my template code:
>
> <div t:type="layouts/General" title="e"
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>     <div t:type="loop" source="recentPosts" value="var:post">
>         <div>${var:post}</div>
>         <div>${var:post.title}</div>
>         <div>${var:post.body}</div>
>         <div>${var:post.created}</div>
>     </div>
> </div>
>
>
> When I run this I get an exception:
>
> "Component blog/Start does not contain a stored render variable with
> name 'post.title'. Stored render variables: post."
>
> So it sees my stored render variable, but thinks post.something
> represents a different property. Having just read the issue at
> https://issues.apache.org/jira/browse/TAPESTRY-1830 it seems that only
> simple objects (probably ending in a toString call?) are supported. Is
> that true, and if so, is that the extent of what will be done? I haven't
> dug in to the code, but couldn't you infer the type based on the type of
> the collection supplied to the source parameter?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org