On Tuesday 15 Nov 2005 04:13, Matt Welch wrote:
> I'm just getting into Tapestry and while I like many of the concepts,
> I'm finding it to be a little complex. Here's an example. It's my
> understanding that specifying components for you pages via annotation
> is new to Tapestry 4.0. I'm a fan of annotations however, in this case
> they seem a little clumsy. Here's an example from my adaptation of the
> tutorial I'm following (Kent Tong's Enjoying Web Development with
> Tapestry):
>
>
> @Component(
>       id="productsLoop",
>       type="For",
>       bindings={
>                       "source=products",
>                       "value=currentProduct",
>                       "element=literal:tr"
>                       }
> )
> public abstract IComponent getProductsFor();

I read some of the answers to your question, and although they were all 
correct, it seemed to me didn't help you as a newbie into tapestry figure out 
what to do.

I assume with the above example, you are refering to a bit in your html 
template where you have done

<span jwcid="productsLoop">
...
</span>

But you could just have easily done

<tr jwcid="@For" source="ognl:products" value="ognl:currentProduct">
...
</tr> 

(you could put this id in front of @For if you want - but if you leave it out 
a default is created for you).  No special java needed (although you will 
have to provide the getProducts method and an abstract method for  
getcurrentProduct within the java class that represents the page.

As youpointed out, if you are unhappy having this logic in your html template 
(because you want to separate out the responsibilities) then put xml into 
your .page file that does the same job.

>
>
> That's how I declared a For component for the eStore tutorial. I guess
> that's really not so bad and my IDE keep the indentation clean so that
> it's not too hard to follow, but to be honest, what I was kind of
> expecting was something a little more code intensive rather than XML
> or annotation intensive. For instance, if the BasePage or AbstractPage
> had a method like addPageComponent() then in some kind of
> intialization method or perhaps the contstructor I might do something
> like:
>
>
> {
>     For productsLoop = new For();
>     products.setId("productsLoop");
>     productsLoop.setSource(getProducts());
>     productsLoop.setValue(getCurrentProduct());
>     productsLoop.setElement("tr");
>     addPageComponent(productsLoop);
> }
>

I must admit having got to this bit I am confused as to what you are trying to 
do.

You seem to be mixing up using a component in a page that already exists in 
the framework - the For component in this case -  which is the way I answered 
the bit above, with declaring your own component to do something for you 
(which them makes use of others components and its own logic.


If you want to see the code intensive part of a component, this is one I made 
for my application - its aim is to output details about a person.  Its called 
(in the syntax used above) from the page as follows

<span jwcid="[EMAIL PROTECTED]" label="Father" person="ognl:person.father"/>

The java, using anotations declares the component and two parameters

===========================================
package uk.org.chandlerfamily.tapestry.components; 
 
/*Copyright (c) 2005 Alan Chandler, licenced under the GPL (see LICENCE.txt 
file in META-INF directory)*/ 
 
import org.apache.tapestry.annotations.*; 
import org.apache.tapestry.BaseComponent; 
import org.apache.tapestry.IPage; 
 
import uk.org.chandlerfamily.sqlmap.famtree.PersonSummary; 
import uk.org.chandlerfamily.tapestry.famtree.Edit; 
import uk.org.chandlerfamily.tapestry.interfaces.*; 
 
@ComponentClass 
public abstract class Person extends BaseComponent { 
 
        @Parameter 
        public abstract PersonSummary getPerson(); 
         
        @Parameter 
        public abstract String getLabel(); 
 
        @InjectPage("Edit") 
        public abstract Edit getEditPage(); 
         
        public IPage doEdit(int personId) { 
            Edit edit = getEditPage(); 
            edit.setPersonId(personId); 
            edit.setFunction(Function.EDIT); 
            return edit; 
        } 
         
}
==========================================

and has an html template with it

<!-- Copyright (c) 2005 Alan Chandler, licenced under the GPL (see LICENCE.txt 
file in META-INF directory) -->
<span jwcid="@If" condition="ognl:person != null">
<table class="person">

<span jwcid="@If" condition="ognl:label != null">
<tr><td id="type" class="label"><span jwcid="@Insert" 
value="ognl:label">Wife</span></td></tr>
</span>

<tr>
<td class="name" id="forename"><a jwcid="@DirectLink" 
listener="listener:doEdit" parameters="ognl:person.id"><span jwcid="@Insert" 
value="ognl:person.forename">Heather</span></a></td>
<td class="name" id="surname"><a jwcid="@DirectLink" 
listener="listener:doEdit" parameters="ognl:person.id"><span 
jwcid="@Insert"value="ognl:person.surname">Hale</span></a></td>
<td class="date"><span jwcid="@Insert" value="ognl:person.DOB">~May 
2005</span></td>
<td class="sex"><span jwcid="@Insert" value="ognl:person.gender">F</span></td>
</tr>
</table>
</span>




>
> I'm guessing that this alternate way of doing things doesn't exist
> since I haven't seen any tutorials or examples that show anything like
> that. Has anyone ever tried to do something like that or would there
> be drastic changes to core framework needed?

Puzzled as what you are trying to achieve that wants this massive change

>
> Again, I'm pretty new to Tapestry so it may be that I'll get used to
> such heavy annotations/XML in time, so take this for what it is: a
> newb's first impressions.

As a newbie myself starting directly with Tapestry 4, I found it strange that 
much of the documentation stems from Tapestry 3 where you HAD to HAVE 
component and page specifications in XML.  I started off trying very hard to 
avoid any, and built most of my code without them.  But then I discovered 
that it was often easier to build a small XML file for a specification of a 
component than do the java instead, so I now have a mixture of both.  If I 
don't need java I use the xml specification - if I need java (for instance in 
the above example to load the Edit Page, and pass it a parameter) then I use 
annotations and don't bother with the specification file.



-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to