You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Gunnar Eketrapp <gu...@gmail.com> on 2009/09/24 14:31:16 UTC

JSP replacement quiz

I am converting jsp that produces a table like ...

1      317
2      45
3      118

... i,e. an index plus a count for that index.

How should you folks do this? Is there a way with .tml to fix this or do I
have to use Grid or write a component.

JSP code
=======
<% int level=1; %>
<c:forEach items="${levels}" var="count">
<tr>
<td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>><%= level %></td>
<td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>>${count}</td>
</tr>
<% ++level; %></c:forEach>

Re: JSP replacement quiz

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 24 Sep 2009 09:31:16 -0300, Gunnar Eketrapp  
<gu...@gmail.com> escreveu:

> I am converting jsp that produces a table like ...
>
> 1      317
> 2      45
> 3      118
> ... i,e. an index plus a count for that index.
> How should you folks do this? Is there a way with .tml to fix this or do  
> I have to use Grid or write a component.

When learning Tapestry, the best way to learn it is to think how you can  
implement something, not trying to replicate JSP behavior in Tapestry.
What do you need to do here? I'm not sure by reading your code. Try to  
explain without using JSP snippets please.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
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: JSP replacement quiz

Posted by Kalle Korhonen <ka...@gmail.com>.
Sure you have an access to the index, just like to the element itself.
Read the documentation. I'd just do all of that logic in the page
class and implement something like getStyleClass().

I don't agree with your "it would be nice if simple loops like this
could be achieved in TML" statement. Having gone through the jsp hell
where designers pretend to be programmers, I much prefer keeping most
of the logic in Java - this goes back to what I said in the other
thread you had started.

Kalle


On Thu, Sep 24, 2009 at 10:23 AM, Gunnar Eketrapp
<gu...@gmail.com> wrote:
> Hi!
>
> It's not that simple ...
>
> The level is displayd as (idx+1) and i dont even have acess to the index or
> do I?
>
> The class="tdalt" that is rendered on each second line can be solved by
> methods.
>
> But I haven't come up with a solution for the index and index+1 problem.
>
> Or am I stupid? Perhaps there is something that I have not grasped ...
>
> I am quite new to T5 ...
>
> I gave up and solved it with a method + outputRaw. I also made a component
> for some other case.
>
> But it would be nice if simple loops like this could be achieved in TML.
>
> Gunnar
>
>
> 2009/9/24 kalle.o.korhonen <ka...@gmail.com>
>
>> You can just use Loop component -
>>
>> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Loop.html
>>
>> Kalle
>>
>> On Thu, Sep 24, 2009 at 5:31 AM, Gunnar Eketrapp
>> <gu...@gmail.com> wrote:
>> > I am converting jsp that produces a table like ...
>> >
>> > 1      317
>> > 2      45
>> > 3      118
>> >
>> > ... i,e. an index plus a count for that index.
>> >
>> > How should you folks do this? Is there a way with .tml to fix this or do
>> I
>> > have to use Grid or write a component.
>> >
>> > JSP code
>> > =======
>> > <% int level=1; %>
>> > <c:forEach items="${levels}" var="count">
>> > <tr>
>> > <td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>><%= level %></td>
>> > <td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>>${count}</td>
>> > </tr>
>> > <% ++level; %></c:forEach>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> [Hem: 08-715 59 57, Mobil: 0708-52 62 90]
> Allévägen 2A, 132 42 Saltsjö-Boo
>

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


Re: JSP replacement quiz

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 24 Sep 2009 14:23:12 -0300, Gunnar Eketrapp  
<gu...@gmail.com> escreveu:

> Hi!

Hi!

> It's not that simple ...
>
> The level is displayd as (idx+1) and i dont even have acess to the index  
> or do I?

Loop's index parameter is the solution.

In your class:

@Property
private int index;

public getLineNumber() {
	return index + 1;
}

Then, in your template:

${lineNumber}

When using Tapestry, think that you do boolean or not null tests in the  
template. Everything eles is better done in the page or component class.

> The class="tdalt" that is rendered on each second line can be solved by
> methods.
> But I haven't come up with a solution for the index and index+1 problem.

They are also solved by methods. See above.

> Or am I stupid? Perhaps there is something that I have not grasped ...

You're not stupid at all. You're just learning a new framework that does  
things very differently (and way better than) than JSP and Struts.

> I gave up and solved it with a method + outputRaw. I also made a  
> component for some other case.

Nice to know that you're a Tapestry newbie but already implemented your  
own components. That's a success story for T5. :)

> But it would be nice if simple loops like this could be achieved in TML.

Don't forget that putting logic in your template is always a bad thing  
(lack of separation of concerns and MVC violation), unless it's looping or  
doing simple conditionals.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
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: JSP replacement quiz

Posted by Gunnar Eketrapp <gu...@gmail.com>.
Hi!

It's not that simple ...

The level is displayd as (idx+1) and i dont even have acess to the index or
do I?

The class="tdalt" that is rendered on each second line can be solved by
methods.

But I haven't come up with a solution for the index and index+1 problem.

Or am I stupid? Perhaps there is something that I have not grasped ...

I am quite new to T5 ...

I gave up and solved it with a method + outputRaw. I also made a component
for some other case.

But it would be nice if simple loops like this could be achieved in TML.

Gunnar


2009/9/24 kalle.o.korhonen <ka...@gmail.com>

> You can just use Loop component -
>
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Loop.html
>
> Kalle
>
> On Thu, Sep 24, 2009 at 5:31 AM, Gunnar Eketrapp
> <gu...@gmail.com> wrote:
> > I am converting jsp that produces a table like ...
> >
> > 1      317
> > 2      45
> > 3      118
> >
> > ... i,e. an index plus a count for that index.
> >
> > How should you folks do this? Is there a way with .tml to fix this or do
> I
> > have to use Grid or write a component.
> >
> > JSP code
> > =======
> > <% int level=1; %>
> > <c:forEach items="${levels}" var="count">
> > <tr>
> > <td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>><%= level %></td>
> > <td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>>${count}</td>
> > </tr>
> > <% ++level; %></c:forEach>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
[Hem: 08-715 59 57, Mobil: 0708-52 62 90]
Allévägen 2A, 132 42 Saltsjö-Boo

Re: JSP replacement quiz

Posted by "kalle.o.korhonen" <ka...@gmail.com>.
You can just use Loop component -
http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Loop.html

Kalle

On Thu, Sep 24, 2009 at 5:31 AM, Gunnar Eketrapp
<gu...@gmail.com> wrote:
> I am converting jsp that produces a table like ...
>
> 1      317
> 2      45
> 3      118
>
> ... i,e. an index plus a count for that index.
>
> How should you folks do this? Is there a way with .tml to fix this or do I
> have to use Grid or write a component.
>
> JSP code
> =======
> <% int level=1; %>
> <c:forEach items="${levels}" var="count">
> <tr>
> <td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>><%= level %></td>
> <td<%= level % 2 == 0 ? " class=\"tdalt\"" : "" %>>${count}</td>
> </tr>
> <% ++level; %></c:forEach>
>

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