[T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Nicolas Bouillon
Hello,

I'm facing a strange behaviour on a component. Here if a sample component :

package tapestry.components;

import org.apache.tapestry5.MarkupWriter;

public class CountComponent {

private Integer count = 0;

public Integer getCount() {
if (count == null) {
count = 1;
} else {
count++;
}
return count;
}

public void beginRender(MarkupWriter writer) {
writer.element(span);
writer.write(- + getCount().toString());
writer.end();
}

}

if if call mutliple type my component like :

t:countComponent /
t:countComponent /

I got the wanted behavior :

- 1
- 1

But if i nest my component into a loop like :

t:loop source=items value=var:item
t:countComponent /
/t:loop

I got this behaviour :

- 1
- 2
etc..

Is this intended or a bug ?

Best regards

Nicolas.



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



Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Katia Aresti Gonzalez
Hi,

No, there is no bug.

In the first example you have 2 components, so two contexts.

In the second one you have just one component, so when you loop into it, it
increases twice, as you are increasing the same component

Katia

2010/5/5 Nicolas Bouillon nico...@bouil.org

 Hello,

 I'm facing a strange behaviour on a component. Here if a sample component :

 package tapestry.components;

 import org.apache.tapestry5.MarkupWriter;

 public class CountComponent {

private Integer count = 0;

public Integer getCount() {
if (count == null) {
count = 1;
} else {
count++;
}
return count;
}

public void beginRender(MarkupWriter writer) {
writer.element(span);
writer.write(- + getCount().toString());
writer.end();
}

 }

 if if call mutliple type my component like :

 t:countComponent /
 t:countComponent /

 I got the wanted behavior :

 - 1
 - 1

 But if i nest my component into a loop like :

 t:loop source=items value=var:item
t:countComponent /
 /t:loop

 I got this behaviour :

 - 1
 - 2
 etc..

 Is this intended or a bug ?

 Best regards

 Nicolas.



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




Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Nicolas Bouillon
Thank you for you fast response.

Very disturbing in fact, because I was using this kind of method in lot of
place... and I don't know if the component will be used alone or in a loop.

So I have to reset such local variable in a @SetupRender each time, or
there is a better solution ?

Thanks.

On Wed, 5 May 2010 17:58:41 +0200, Katia Aresti Gonzalez
katiaare...@gmail.com wrote:
 Hi,
 
 No, there is no bug.
 
 In the first example you have 2 components, so two contexts.
 
 In the second one you have just one component, so when you loop into it,
it
 increases twice, as you are increasing the same component
 
 Katia
 
 2010/5/5 Nicolas Bouillon nico...@bouil.org
 
 Hello,

 I'm facing a strange behaviour on a component. Here if a sample
component
 :

 package tapestry.components;

 import org.apache.tapestry5.MarkupWriter;

 public class CountComponent {

private Integer count = 0;

public Integer getCount() {
if (count == null) {
count = 1;
} else {
count++;
}
return count;
}

public void beginRender(MarkupWriter writer) {
writer.element(span);
writer.write(- + getCount().toString());
writer.end();
}

 }

 if if call mutliple type my component like :

 t:countComponent /
 t:countComponent /

 I got the wanted behavior :

 - 1
 - 1

 But if i nest my component into a loop like :

 t:loop source=items value=var:item
t:countComponent /
 /t:loop

 I got this behaviour :

 - 1
 - 2
 etc..

 Is this intended or a bug ?

 Best regards

 Nicolas.



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



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



Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Katia Aresti Gonzalez
If nobody desagrees, I think SetupRender is the place to initialize the
render variables.
Anyway, your component seems very simple ;  I don't know exactly which will
be useful for You could use component parameters...
I depends on the component...

2010/5/5 Nicolas Bouillon nico...@bouil.org

 Thank you for you fast response.

 Very disturbing in fact, because I was using this kind of method in lot of
 place... and I don't know if the component will be used alone or in a loop.

 So I have to reset such local variable in a @SetupRender each time, or
 there is a better solution ?

 Thanks.

 On Wed, 5 May 2010 17:58:41 +0200, Katia Aresti Gonzalez
 katiaare...@gmail.com wrote:
  Hi,
 
  No, there is no bug.
 
  In the first example you have 2 components, so two contexts.
 
  In the second one you have just one component, so when you loop into it,
 it
  increases twice, as you are increasing the same component
 
  Katia
 
  2010/5/5 Nicolas Bouillon nico...@bouil.org
 
  Hello,
 
  I'm facing a strange behaviour on a component. Here if a sample
 component
  :
 
  package tapestry.components;
 
  import org.apache.tapestry5.MarkupWriter;
 
  public class CountComponent {
 
 private Integer count = 0;
 
 public Integer getCount() {
 if (count == null) {
 count = 1;
 } else {
 count++;
 }
 return count;
 }
 
 public void beginRender(MarkupWriter writer) {
 writer.element(span);
 writer.write(- + getCount().toString());
 writer.end();
 }
 
  }
 
  if if call mutliple type my component like :
 
  t:countComponent /
  t:countComponent /
 
  I got the wanted behavior :
 
  - 1
  - 1
 
  But if i nest my component into a loop like :
 
  t:loop source=items value=var:item
 t:countComponent /
  /t:loop
 
  I got this behaviour :
 
  - 1
  - 2
  etc..
 
  Is this intended or a bug ?
 
  Best regards
 
  Nicolas.
 
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
  For additional commands, e-mail: users-h...@tapestry.apache.org
 
 

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




Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Nicolas Bouillon
Yes, this sample component is really simple, it was just a test case.

My real component takes is used to display the product price in an order
from the client cart (many lines, so in a loop). And as local variable I
had the discount so once a discount was found for a line, it was kept
for all the following lines... not very good for business !

On Wed, 5 May 2010 18:09:03 +0200, Katia Aresti Gonzalez
katiaare...@gmail.com wrote:
 If nobody desagrees, I think SetupRender is the place to initialize the
 render variables.
 Anyway, your component seems very simple ;  I don't know exactly which
will
 be useful for You could use component parameters...
 I depends on the component...
 
 2010/5/5 Nicolas Bouillon nico...@bouil.org
 
 Thank you for you fast response.

 Very disturbing in fact, because I was using this kind of method in lot
 of
 place... and I don't know if the component will be used alone or in a
 loop.

 So I have to reset such local variable in a @SetupRender each time, or
 there is a better solution ?

 Thanks.

 On Wed, 5 May 2010 17:58:41 +0200, Katia Aresti Gonzalez
 katiaare...@gmail.com wrote:
  Hi,
 
  No, there is no bug.
 
  In the first example you have 2 components, so two contexts.
 
  In the second one you have just one component, so when you loop into
  it,
 it
  increases twice, as you are increasing the same component
 
  Katia
 
  2010/5/5 Nicolas Bouillon nico...@bouil.org
 
  Hello,
 
  I'm facing a strange behaviour on a component. Here if a sample
 component
  :
 
  package tapestry.components;
 
  import org.apache.tapestry5.MarkupWriter;
 
  public class CountComponent {
 
 private Integer count = 0;
 
 public Integer getCount() {
 if (count == null) {
 count = 1;
 } else {
 count++;
 }
 return count;
 }
 
 public void beginRender(MarkupWriter writer) {
 writer.element(span);
 writer.write(- + getCount().toString());
 writer.end();
 }
 
  }
 
  if if call mutliple type my component like :
 
  t:countComponent /
  t:countComponent /
 
  I got the wanted behavior :
 
  - 1
  - 1
 
  But if i nest my component into a loop like :
 
  t:loop source=items value=var:item
 t:countComponent /
  /t:loop
 
  I got this behaviour :
 
  - 1
  - 2
  etc..
 
  Is this intended or a bug ?
 
  Best regards
 
  Nicolas.
 
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
  For additional commands, e-mail: users-h...@tapestry.apache.org
 
 

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



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



Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Thiago H. de Paula Figueiredo
On Wed, 05 May 2010 12:55:47 -0300, Nicolas Bouillon nico...@bouil.org  
wrote:



Hello,


Hi!


if if call mutliple type my component like :

t:countComponent /
t:countComponent /


You have two different instances (objects) of your count component.


t:loop source=items value=var:item
t:countComponent /
/t:loop


Now you have one instance being rendered twice.


Is this intended or a bug ?


This is how Tapestry works. Static structure, dynamic behavior. ;)

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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



Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Thiago H. de Paula Figueiredo
On Wed, 05 May 2010 13:02:26 -0300, Nicolas Bouillon nico...@bouil.org  
wrote:



Thank you for you fast response.

Very disturbing in fact, because I was using this kind of method in lot  
of place... and I don't know if the component will be used alone or in a  
loop.


By the way, *never* give an initial value to a field in a component, page  
or mixin class. Every field that hasn't annotations (except @Property and  
@Retain), after a request, is set to its initial value (the one defined in  
its declaration). Tapestry page instances are pooled. Read more about the  
pool in the Principle 1 --
Static Structure, Dynamic Behavior session of  
http://tapestry.apache.org/tapestry5.1/.



So I have to reset such local variable in a @SetupRender each time, or
there is a better solution ?


Use @SetupRender.

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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



Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Thiago H. de Paula Figueiredo
On Wed, 05 May 2010 13:13:09 -0300, Nicolas Bouillon nico...@bouil.org  
wrote:



My real component takes is used to display the product price in an order
from the client cart (many lines, so in a loop). And as local variable I
had the discount so once a discount was found for a line, it was kept
for all the following lines... not very good for business !


You need to pass the discount as a parameter to your component.

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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



Re: [T5.1] Strange behaviour of component method (with lazy init). Bug ?

2010-05-05 Thread Katia Aresti Gonzalez
What I meaned to say with the perfect explanation... :)
Thank you! :)

2010/5/5 Thiago H. de Paula Figueiredo thiag...@gmail.com

 On Wed, 05 May 2010 13:13:09 -0300, Nicolas Bouillon nico...@bouil.org
 wrote:

  My real component takes is used to display the product price in an order
 from the client cart (many lines, so in a loop). And as local variable I
 had the discount so once a discount was found for a line, it was kept
 for all the following lines... not very good for business !


 You need to pass the discount as a parameter to your component.


 --
 Thiago H. de Paula Figueiredo
 Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
 and instructor
 Owner, Ars Machina Tecnologia da Informação Ltda.
 http://www.arsmachina.com.br

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