You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Russell Brown <Ru...@ioko.com> on 2008/10/06 12:07:53 UTC

T5: equivelent of c:set ?

Hi,

If I want to set some property from within the component template is
that possible in Tapestry 5? Something like the c:set tag is JSP jstl?
Or do you just write a set component and have it as a property of the
containing component?

 

Cheers

 

Russell


RE: T5: equivelent of c:set ?

Posted by Russell Brown <Ru...@ioko.com>.
I get it. Thanks. 

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: 06 October 2008 15:28
To: Tapestry users
Subject: Re: T5: equivelent of c:set ?

Em Mon, 06 Oct 2008 11:01:34 -0300, Russell Brown
<Ru...@ioko.com>  
escreveu:

> In jsp
>
> <c:forEach items="${someList}" var="myItem"
> 		   varStatus="counter">
>
> <c:if test="${!empty someVar}">
> 	<somemarkup attr="$someVar}"/>
> </c:if>
> <someothermarkup/>
>
> <c:set var="someVar" value="${myItem.myProperty}"/>
>
> </c:forEach>

You don't need to create a component from that, just stop thinking JSP  
when coding Tapestry. :)
In Tapestry, all the logic is implemented in pages classes, with no
logic  
in templates. And this is a very good thing, as the logic is easily
tested  
when implemented in classes. ;)

Not tested, but hopefully it will give you an idea on how to do that:

YourClass.java:

private ItemType item;

@Property /* so we don't need to provide the getter and setter, as they

don't have any logic */
private ItemType lastItem;

public ItemType getItem() {
	return item;
}

public void ItemType setItem(ItemType item) {
	lastItem = this.item;
	this.item = item;
}

public List getList() {
	return ...; // list to be iterated
}

public boolean isNotEmpty() {
	return lastItem != null; // or any other logic
}

YourTemplate.tml:

<t:loop source="list" value="item">
	<t:if test="notEmpty">
		<somemarkup attr="${lastItem.myProperty}"/>	
	</t:if>
	<someothermarkup/>
</t:loop>

If you don't get it, tell us. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
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


Re: T5: equivelent of c:set ?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 06 Oct 2008 11:01:34 -0300, Russell Brown <Ru...@ioko.com>  
escreveu:

> In jsp
>
> <c:forEach items="${someList}" var="myItem"
> 		   varStatus="counter">
>
> <c:if test="${!empty someVar}">
> 	<somemarkup attr="$someVar}"/>
> </c:if>
> <someothermarkup/>
>
> <c:set var="someVar" value="${myItem.myProperty}"/>
>
> </c:forEach>

You don't need to create a component from that, just stop thinking JSP  
when coding Tapestry. :)
In Tapestry, all the logic is implemented in pages classes, with no logic  
in templates. And this is a very good thing, as the logic is easily tested  
when implemented in classes. ;)

Not tested, but hopefully it will give you an idea on how to do that:

YourClass.java:

private ItemType item;

@Property /* so we don't need to provide the getter and setter, as they  
don't have any logic */
private ItemType lastItem;

public ItemType getItem() {
	return item;
}

public void ItemType setItem(ItemType item) {
	lastItem = this.item;
	this.item = item;
}

public List getList() {
	return ...; // list to be iterated
}

public boolean isNotEmpty() {
	return lastItem != null; // or any other logic
}

YourTemplate.tml:

<t:loop source="list" value="item">
	<t:if test="notEmpty">
		<somemarkup attr="${lastItem.myProperty}"/>	
	</t:if>
	<someothermarkup/>
</t:loop>

If you don't get it, tell us. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

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


RE: T5: equivelent of c:set ?

Posted by Russell Brown <Ru...@ioko.com>.
Ok...an example

In jsp

<c:forEach items="${someList}" var="myItem"
		   varStatus="counter">

<c:if test="${!empty someVar}">
	<somemarkup attr="$someVar}"/>
</c:if>
<someothermarkup/>

<c:set var="someVar" value="${myItem.myProperty}"/>

</c:forEach>

So in the above example I have a variable available called "someVar"
that is set to the value of the previous myItem's myProperty value. But
with T5 and the var binding I get THIS iterations value. The SCOPE of
the VAR binding is not wide enough for me. So is there an equivalent in
Tapestry or do I have to create a component and call it like this

<t:loop source="someList" value="myItem" index="counter">

<t:if test="someVar">
	<somemarkup attr="${someVar.value}"/>
</t:if>
<someothermarkup/>

<t:mypackage.set value="${myItem.myProperty}" t:id="someVar"/>


</t:loop>

And then have code like 

@Component(id="someVar")
Private MySetComponentType someVar;


And the MySetComponentType is just 

Public class MySetComponentType {
	@Parameter
	@Property
	Private String value;

}


But there just has to be a better way. Right?

Cheers for taking the time

Russell

-----Original Message-----
From: Kristian Marinkovic [mailto:kristian.marinkovic@porsche.co.at] 
Sent: 06 October 2008 14:22
To: Tapestry users
Subject: Re: T5: equivelent of c:set ?

if you use the "var:" prefix in your template you do not need a
corresponding property in your page/component. and you 
can use this variable in your template multiple times (as in the
loop example). tapestry will generate a property on the fly
during rendering for this variable.

if you declare your components purley in your template
you can also pass in the parameters it accepts as well. 
.... and it should work with var: variables as well.

eg.
<ul>
    <li t:type="loop" source="1..10" value="var:index">
    <t:actionlink context="${var:index}">link</t:actionlink>
    </li>
</ul>

AFAIK you cannot access the value of the "var:" variables in your
pages or components.

hope this helps... maybe you can post an example... as posted by thiago

g,
kris




"Thiago H. de Paula Figueiredo" <th...@gmail.com> 
06.10.2008 15:10
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
"Tapestry users" <us...@tapestry.apache.org>
Kopie

Thema
Re: T5: equivelent of c:set ?







Em Mon, 06 Oct 2008 09:01:48 -0300, Russell Brown
<Ru...@ioko.com> 
 
escreveu:

> As far as I can see it is only of use in a loop in which case it is
set
> at the start of the iteration. How about iteration idioms that involve
> setting a value at the end of the iteration to be used by the next
> iteration? It is fairly common to see and trivial in struts, jsps,
> spring mvc etc, etc.

You can do that in Tapestry, but you just do it in a different way. 
Remember that the page class properties are always available to the 
template.

Please post a JSP example of what you're trying to accomplish so we'll
can 
 
help you better. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
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


Re: T5: equivelent of c:set ?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
if you use the "var:" prefix in your template you do not need a
corresponding property in your page/component. and you 
can use this variable in your template multiple times (as in the
loop example). tapestry will generate a property on the fly
during rendering for this variable.

if you declare your components purley in your template
you can also pass in the parameters it accepts as well. 
.... and it should work with var: variables as well.

eg.
<ul>
    <li t:type="loop" source="1..10" value="var:index">
    <t:actionlink context="${var:index}">link</t:actionlink>
    </li>
</ul>

AFAIK you cannot access the value of the "var:" variables in your
pages or components.

hope this helps... maybe you can post an example... as posted by thiago

g,
kris




"Thiago H. de Paula Figueiredo" <th...@gmail.com> 
06.10.2008 15:10
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
"Tapestry users" <us...@tapestry.apache.org>
Kopie

Thema
Re: T5: equivelent of c:set ?







Em Mon, 06 Oct 2008 09:01:48 -0300, Russell Brown <Ru...@ioko.com> 
 
escreveu:

> As far as I can see it is only of use in a loop in which case it is set
> at the start of the iteration. How about iteration idioms that involve
> setting a value at the end of the iteration to be used by the next
> iteration? It is fairly common to see and trivial in struts, jsps,
> spring mvc etc, etc.

You can do that in Tapestry, but you just do it in a different way. 
Remember that the page class properties are always available to the 
template.

Please post a JSP example of what you're trying to accomplish so we'll can 
 
help you better. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

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



Re: T5: equivelent of c:set ?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 06 Oct 2008 09:01:48 -0300, Russell Brown <Ru...@ioko.com>  
escreveu:

> As far as I can see it is only of use in a loop in which case it is set
> at the start of the iteration. How about iteration idioms that involve
> setting a value at the end of the iteration to be used by the next
> iteration? It is fairly common to see and trivial in struts, jsps,
> spring mvc etc, etc.

You can do that in Tapestry, but you just do it in a different way.  
Remember that the page class properties are always available to the  
template.

Please post a JSP example of what you're trying to accomplish so we'll can  
help you better. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

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


RE: T5: equivelent of c:set ?

Posted by Russell Brown <Ru...@ioko.com>.
Thanks. I have already.

The docs say "Allows a render variable of the component to be read or
updated." Updated how, when? What is a render variable? A variable in a
template without a corresponding property? But I want to SET a property
of my component from the template...

As far as I can see it is only of use in a loop in which case it is set
at the start of the iteration. How about iteration idioms that involve
setting a value at the end of the iteration to be used by the next
iteration? It is fairly common to see and trivial in struts, jsps,
spring mvc etc, etc.

Is there a way to do this in T5?

Cheers

Russell

-----Original Message-----
From: Kristian Marinkovic [mailto:kristian.marinkovic@porsche.co.at] 
Sent: 06 October 2008 11:57
To: Tapestry users
Subject: Re: T5: equivelent of c:set ?

hi Russell,

take a look at the "var:" binding 
http://tapestry.apache.org/tapestry5/guide/parameters.html


g,
kris




"Russell Brown" <Ru...@ioko.com> 
06.10.2008 12:07
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
"Tapestry users" <us...@tapestry.apache.org>
Kopie

Thema
T5: equivelent of c:set ?






Hi,

If I want to set some property from within the component template is
that possible in Tapestry 5? Something like the c:set tag is JSP jstl?
Or do you just write a set component and have it as a property of the
containing component?

 

Cheers

 

Russell



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


Re: T5: equivelent of c:set ?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi Russell,

take a look at the "var:" binding 
http://tapestry.apache.org/tapestry5/guide/parameters.html


g,
kris




"Russell Brown" <Ru...@ioko.com> 
06.10.2008 12:07
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
"Tapestry users" <us...@tapestry.apache.org>
Kopie

Thema
T5: equivelent of c:set ?






Hi,

If I want to set some property from within the component template is
that possible in Tapestry 5? Something like the c:set tag is JSP jstl?
Or do you just write a set component and have it as a property of the
containing component?

 

Cheers

 

Russell