Re: New to Tapestry- Lots of questions sorry!

2009-03-21 Thread Thiago H. de Paula Figueiredo
Em Sat, 21 Mar 2009 04:06:13 -0300, Amit Nithian   
escreveu:



Also can you explain what this does?
 @Parameter(required=true)
 private String ccNumber


This is used to declare a component parameter, not being used in pages.

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

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



Re: New to Tapestry- Lots of questions sorry!

2009-03-21 Thread Robert Zeigler

Nah, you wouldn't need that.  You can do things like:

.tml:
...

.java:
public String getTransactionClass() {
  switch(transactionType) {
 case ACCEPTED: return "validtransaction";
 case DECLINED: return "declinedtransaction";
 default: return "";
}

And so forth.

You can also do things like choose specific pieces to render via  
"t:block" and the "delegate" component:





  ... stuff in here



  ... other stuff in here


.java:

@Inject
private ComponentResources resources;
public Block getTransactionBlock() {
switch(transactionType) {
case ACCEPTED: return  
resources.getBlock("acceptedTransactionBlock");

default: return resources.getBlock("declinedTransactionBlock");
}
}


All of this is to say that there are many ways to make your displayed  
content highly dynamic, all while keeping the structure of the page  
static.


Robert

On Mar 21, 2009, at 3/212:06 AM , Amit Nithian wrote:

Thanks both for your answers! They were helpful. I guess my angle  
was more

from an older ASP web application paradigm or even old style PHP which
didn't have much distinction with models, views, and controllers. My  
only
question/complaint about the jumping back and forth between the  
template and
Page class is what do you do when you want to do different things  
based on
something like an enum instead of simply a boolean? Would you have  
to have
multiple boolean functions one for each possible enum value that you  
wish to

test?
For example, if I have (using a credit card theme here) an enum for a
transaction status with values of DECLINED and ACCEPTED, if I want to
display ACCEPTED in green and DECLINED in red, would I have to have  
two
functions isDeclined and isAccepted and do an t:if to control red  
and green
display? Sometimes here, I feel, is where having scripting  
capability helps
in the display of the page to prevent a page class with a ton of  
simple

getter methods.

Also can you explain what this does?
 @Parameter(required=true)
  private String ccNumber

Thanks again and I'm excited to continue using Tapestry!

- Amit


On Fri, Mar 20, 2009 at 6:10 AM, Christian Edward Gruber <
christianedwardgru...@gmail.com> wrote:

Thiago, I think he's misunderstanding the point of Tapestry.  You  
never do
scripting in the views.  In fact, you never do scripting.   
Scripting (in web
templates) mixes display layout and display flow with business  
logic, data
flow, and user workflow.  They're all mixed up together.  Anyone  
used to
that will have a hard time seeing how to accomplish the same  
features in
their application without access to any ability to embed scripted  
code into

the view.

Amit, you need to re-think your orientation when using something like
Tapestry.  All of your code is in controllers, with the exception  
of some

display layout flows like loops, conditionals, and such.  There are
components for these, but unlike JSP tags, they do not "unwind"  
into code,
they are components and all the pages are composed, with a  
rendering engine
that asks components to render themselves or their templates, and  
their
child components, who are in turn asked to render.  It's a very  
different

paradigm.

In practice though, if you're thinking of having a lot of logic you  
would
imagine going into scriptlets or the like, factor that code into  
methods
which return the displayable result.  For instance (this code is  
made up on

the spot):

<%
  CreditCard cc =
myDao.getCreditCardByNumber(request.getProperty("ccNumber"));
%>
<%=cc.getType().getName()%> card
Card <%=cc.getNumber()%> has the following purchases today:
DateVendorAmountPosted?th>

<%
  List txns =
myDao.getTransactionsForCC(cc.getNumber());
  for (CCTransaction txn: txns) { %>
  
  <%=MyUtil.format(txn.getDate())%>
  <%=txn.getVendor()%>
  <%=MyUtil.formatCurrency(txn.getAmount(),"USD") 
%>

  <%=txn.isPosted()%>
  
<%  }  %>


The above is pretty ugly JSP code, and even with Struts or other  
web MVC
frameworks that use JSPs as a base, it can be that ugly.  Tapestry  
goes a

different way. (this code was also cooked up at 8am after a red-eye
flight... it is uncompiled, let alone untested.  Don't cut-and- 
paste it.
This example uses credit card, but doesn't authenticate and is  
massively

insecure.  It's only paying attention to a certain aspect of things.)

MyPage.java
...
public class MyPage {

  @Inject
  private MyDao myDao;

  @Property
  private CCTransaction currentTransaction;

  @Parameter(required=true)
  private String ccNumber;

  @Property
  private CreditCard creditCard;

  @SetupRender
  public void init() {
  //do validation stuff...
  creditCard = myDao.getCreditCardByNumber(ccNumber);
  }

  public List getTransactions() {

  }

}

MyPage.tml
http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
.
${creditCard.type

Re: New to Tapestry- Lots of questions sorry!

2009-03-21 Thread Amit Nithian
Thanks both for your answers! They were helpful. I guess my angle was more
from an older ASP web application paradigm or even old style PHP which
didn't have much distinction with models, views, and controllers. My only
question/complaint about the jumping back and forth between the template and
Page class is what do you do when you want to do different things based on
something like an enum instead of simply a boolean? Would you have to have
multiple boolean functions one for each possible enum value that you wish to
test?
For example, if I have (using a credit card theme here) an enum for a
transaction status with values of DECLINED and ACCEPTED, if I want to
display ACCEPTED in green and DECLINED in red, would I have to have two
functions isDeclined and isAccepted and do an t:if to control red and green
display? Sometimes here, I feel, is where having scripting capability helps
in the display of the page to prevent a page class with a ton of simple
getter methods.

Also can you explain what this does?
  @Parameter(required=true)
   private String ccNumber

Thanks again and I'm excited to continue using Tapestry!

- Amit


On Fri, Mar 20, 2009 at 6:10 AM, Christian Edward Gruber <
christianedwardgru...@gmail.com> wrote:

> Thiago, I think he's misunderstanding the point of Tapestry.  You never do
> scripting in the views.  In fact, you never do scripting.  Scripting (in web
> templates) mixes display layout and display flow with business logic, data
> flow, and user workflow.  They're all mixed up together.  Anyone used to
> that will have a hard time seeing how to accomplish the same features in
> their application without access to any ability to embed scripted code into
> the view.
>
> Amit, you need to re-think your orientation when using something like
> Tapestry.  All of your code is in controllers, with the exception of some
> display layout flows like loops, conditionals, and such.  There are
> components for these, but unlike JSP tags, they do not "unwind" into code,
> they are components and all the pages are composed, with a rendering engine
> that asks components to render themselves or their templates, and their
> child components, who are in turn asked to render.  It's a very different
> paradigm.
>
> In practice though, if you're thinking of having a lot of logic you would
> imagine going into scriptlets or the like, factor that code into methods
> which return the displayable result.  For instance (this code is made up on
> the spot):
>
> <%
>CreditCard cc =
> myDao.getCreditCardByNumber(request.getProperty("ccNumber"));
> %>
> <%=cc.getType().getName()%> card
> Card <%=cc.getNumber()%> has the following purchases today:
> DateVendorAmountPosted?
> <%
>List txns =
> myDao.getTransactionsForCC(cc.getNumber());
>for (CCTransaction txn: txns) { %>
>
><%=MyUtil.format(txn.getDate())%>
><%=txn.getVendor()%>
><%=MyUtil.formatCurrency(txn.getAmount(),"USD")%>
><%=txn.isPosted()%>
>
> <%  }  %>
>
>
> The above is pretty ugly JSP code, and even with Struts or other web MVC
> frameworks that use JSPs as a base, it can be that ugly.  Tapestry goes a
> different way. (this code was also cooked up at 8am after a red-eye
> flight... it is uncompiled, let alone untested.  Don't cut-and-paste it.
>  This example uses credit card, but doesn't authenticate and is massively
> insecure.  It's only paying attention to a certain aspect of things.)
>
> MyPage.java
> ...
> public class MyPage {
>
>@Inject
>private MyDao myDao;
>
>@Property
>private CCTransaction currentTransaction;
>
>@Parameter(required=true)
>private String ccNumber;
>
>@Property
>private CreditCard creditCard;
>
>@SetupRender
>public void init() {
>//do validation stuff...
>creditCard = myDao.getCreditCardByNumber(ccNumber);
>}
>
>public List getTransactions() {
>
>}
>
> }
>
> MyPage.tml
> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> .
> ${creditCard.type} card
> Card ${creditCard.number} has the following purchases today:
>
> 
>DateVendorAmountPosted?
>
> t:value="currentTransaction.date"/>
>${currentTransaction.getVendor}
>USD ${currentTransaction.amount}>
>${currentTransaction.isPosted}
>
> 
>
> The display logic and flow control is in the template, but no actual data
> lookups or business calculations.  I don't know if it helps, but hopefully
> it gives you a taste of how things are different.
>
> On this note, it might be good to have some side-by-side mini-examples
> which show how someone would do something in vanilla JSP, in Struts, in JSF,
> and in Tapestry so people can make the mental leap.  Annoying to build, I
> know, but potentially highly useful.
>
> regards,
> Christian.
>
>
>

Re: New to Tapestry- Lots of questions sorry!

2009-03-20 Thread Christian Edward Gruber
Thiago, I think he's misunderstanding the point of Tapestry.  You  
never do scripting in the views.  In fact, you never do scripting.   
Scripting (in web templates) mixes display layout and display flow  
with business logic, data flow, and user workflow.  They're all mixed  
up together.  Anyone used to that will have a hard time seeing how to  
accomplish the same features in their application without access to  
any ability to embed scripted code into the view.


Amit, you need to re-think your orientation when using something like  
Tapestry.  All of your code is in controllers, with the exception of  
some display layout flows like loops, conditionals, and such.  There  
are components for these, but unlike JSP tags, they do not "unwind"  
into code, they are components and all the pages are composed, with a  
rendering engine that asks components to render themselves or their  
templates, and their child components, who are in turn asked to  
render.  It's a very different paradigm.


In practice though, if you're thinking of having a lot of logic you  
would imagine going into scriptlets or the like, factor that code into  
methods which return the displayable result.  For instance (this code  
is made up on the spot):


<%
	CreditCard cc =  
myDao.getCreditCardByNumber(request.getProperty("ccNumber"));	

%>
<%=cc.getType().getName()%> card
Card <%=cc.getNumber()%> has the following purchases today:
DateVendorAmountPosted?th>

<%
List txns = myDao.getTransactionsForCC(cc.getNumber());
for (CCTransaction txn: txns) { %>

<%=MyUtil.format(txn.getDate())%>
<%=txn.getVendor()%>
<%=MyUtil.formatCurrency(txn.getAmount(),"USD")%>
<%=txn.isPosted()%>

<%   }  %>


The above is pretty ugly JSP code, and even with Struts or other web  
MVC frameworks that use JSPs as a base, it can be that ugly.  Tapestry  
goes a different way. (this code was also cooked up at 8am after a red- 
eye flight... it is uncompiled, let alone untested.  Don't cut-and- 
paste it.  This example uses credit card, but doesn't authenticate and  
is massively insecure.  It's only paying attention to a certain aspect  
of things.)


MyPage.java
...
public class MyPage {

@Inject
private MyDao myDao;

@Property
private CCTransaction currentTransaction;

@Parameter(required=true)
private String ccNumber;

@Property
private CreditCard creditCard;

@SetupRender
public void init() {
//do validation stuff...
creditCard = myDao.getCreditCardByNumber(ccNumber);
}

public List getTransactions() {

}

}

MyPage.tml
http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
.
${creditCard.type} card
Card ${creditCard.number} has the following purchases today:


DateVendorAmountPosted?

		t:value="currentTransaction.date"/>

${currentTransaction.getVendor}
USD ${currentTransaction.amount}>
${currentTransaction.isPosted}



The display logic and flow control is in the template, but no actual  
data lookups or business calculations.  I don't know if it helps, but  
hopefully it gives you a taste of how things are different.


On this note, it might be good to have some side-by-side mini-examples  
which show how someone would do something in vanilla JSP, in Struts,  
in JSF, and in Tapestry so people can make the mental leap.  Annoying  
to build, I know, but potentially highly useful.


regards,
Christian.


On 20-Mar-09, at 08:07 , Thiago H. de Paula Figueiredo wrote:

On Fri, Mar 20, 2009 at 1:53 AM, Amit Nithian   
wrote:
1) With Tapestry, I understand the Controller is effectively the  
Page and

Components with the View being the template files. I haven't seen any
examples of complex "scripting" in the templates where you can  
build complex

views.


Please give us an example. Your description is a vague enough for me
to not understand what you're talking about.


How do people build nice looking, complex front ends with Tapestry
backends?


Again, I don't know exactly what you're talking about. Anything you
can do with HTML, CSS and JavaScript you can do with Tapestry.
Tapestry deals with the server side of things, but also helps with
some JavaScript issues, specially AJAX.

--
Thiago

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



Christian Edward Gruber
e-mail: christianedwardgru...@gmail.com
weblog: http://www.geekinasuit.com/


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



Re: New to Tapestry- Lots of questions sorry!

2009-03-20 Thread Thiago H. de Paula Figueiredo
On Fri, Mar 20, 2009 at 1:53 AM, Amit Nithian  wrote:
> 1) With Tapestry, I understand the Controller is effectively the Page and
> Components with the View being the template files. I haven't seen any
> examples of complex "scripting" in the templates where you can build complex
> views.

Please give us an example. Your description is a vague enough for me
to not understand what you're talking about.

> How do people build nice looking, complex front ends with Tapestry
> backends?

Again, I don't know exactly what you're talking about. Anything you
can do with HTML, CSS and JavaScript you can do with Tapestry.
Tapestry deals with the server side of things, but also helps with
some JavaScript issues, specially AJAX.

-- 
Thiago

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



Re: New to Tapestry- Lots of questions sorry!

2009-03-20 Thread Otho
Hi Amit,

1) For exmple:


  


  whatever

  


2) You can use whatever you want as long as you manage to pass the data to
tapestry and back. Look at the wiki
http://wiki.apache.org/tapestry/Tapestry5HowTos for examples about GWT for
example.

3) Tapestry is component oriented, while the others are mvc frameworks.
Pages in Tapestry are effectively not controllers in the MVC sense, but more
aggregators of components and services which in turn can consist of
components and services, which in turn... In Tapestry you build your own
building blocks or use predefined ones to assemble the functionality that
you want. If you do more complex things this differs quite much from the MVC
approach where controllers tend to get bloated (at least they do for me ;)
). Furthermore you have a completely different programming model thanks to
the annotation driven approach and the Tapestry IOC which makes many things
just so much simpler. RoR I cannot say much about, since I don't program in
Ruby. Grails is certanly a nice choice for applications which have only one
database, but it is somewhat more difficult to debug thanks to the dynamic
nature of Groovy (no static typechecking can lead to interesting bugs very
easily). I guess the same goes for Ruby. What is better for you in certain
circumstances or for a specific jobs is nothing wich anyone here could
answer, though.

2009/3/20 Amit Nithian 

> Hi all,
> My apologies if my questions are ignorant or have been answered already, if
> so, a link to the answer is more than satisfactory for the question.
> Basically, I am interested in learning one of the many web frameworks and
> have narrowed to looking at Java frameworks since I don't have enough
> experience in PHP, Python or more recently Ruby (and Rails) and I am a Java
> developer. In looking online, I came across Tapestry and am using that now
> to write a simple web application for work and ultimately, I am interested
> in learning how to use Tapestry to write larger scale web applications.
>
> I understand the MVC pattern to some end as it applies to Ruby on Rails
> (and
> subsequently Grails). My questions are as follows;
> 1) With Tapestry, I understand the Controller is effectively the Page and
> Components with the View being the template files. I haven't seen any
> examples of complex "scripting" in the templates where you can build
> complex
> views. Is that by design or am I missing something? For example, I am using
> the GridLayout component and I added an extra "delete" column; however, I
> would like to only enable the "Delete" link inside this phony column only
> if
> some condition on the current bean is true. How would I go about that?
> 2) I saw some discussion regarding JQuery vs Prototype etc which is fine (
> I
> don't know either one well) but how does one go about writing complex UIs
> using Tapestry and template files? Do you use YUI components inside a
> ? How do people build nice looking, complex front ends with
> Tapestry
> backends?
> 3) What are the differences conceptually between Tapestry and Grails or
> Ruby
> on Rails, Spring MVC etc and why is Tapestry better?
>
> Thanks for reading and I am excited about using Tapestry!
> - Amit
>


New to Tapestry- Lots of questions sorry!

2009-03-19 Thread Amit Nithian
Hi all,
My apologies if my questions are ignorant or have been answered already, if
so, a link to the answer is more than satisfactory for the question.
Basically, I am interested in learning one of the many web frameworks and
have narrowed to looking at Java frameworks since I don't have enough
experience in PHP, Python or more recently Ruby (and Rails) and I am a Java
developer. In looking online, I came across Tapestry and am using that now
to write a simple web application for work and ultimately, I am interested
in learning how to use Tapestry to write larger scale web applications.

I understand the MVC pattern to some end as it applies to Ruby on Rails (and
subsequently Grails). My questions are as follows;
1) With Tapestry, I understand the Controller is effectively the Page and
Components with the View being the template files. I haven't seen any
examples of complex "scripting" in the templates where you can build complex
views. Is that by design or am I missing something? For example, I am using
the GridLayout component and I added an extra "delete" column; however, I
would like to only enable the "Delete" link inside this phony column only if
some condition on the current bean is true. How would I go about that?
2) I saw some discussion regarding JQuery vs Prototype etc which is fine ( I
don't know either one well) but how does one go about writing complex UIs
using Tapestry and template files? Do you use YUI components inside a
? How do people build nice looking, complex front ends with Tapestry
backends?
3) What are the differences conceptually between Tapestry and Grails or Ruby
on Rails, Spring MVC etc and why is Tapestry better?

Thanks for reading and I am excited about using Tapestry!
- Amit