You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by smithfox <ss...@gmail.com> on 2007/09/07 03:10:10 UTC

T5: How to bind composite class' field(like sale.product.price) in page template

I wrote:

<input t:type="TextField" t:id="sale.product.price"/>

class Sale{ 
  public Product getProduct(){return this.product};
  public void setProduct(Product product){this.product=product};
}

class Product{  private double price;}

but can't pass.
-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12534271
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
Maybe nested component id is for "Event Bubbling".
But I think should instead separator '.' with another separator.
Because '.' is regarded as spearator of bussiness object,such as
"sale.product.price", just as Tapestry4.x do.
-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12536356
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
The exception:
#
org.apache.tapestry.internal.structure.ComponentPageElementImpl.getEmbeddedElement(ComponentPageElementImpl.java:831)
#
org.apache.tapestry.internal.structure.PageImpl.getComponentElementByNestedId(PageImpl.java:83)
#
org.apache.tapestry.internal.services.ComponentSourceImpl.getComponent(ComponentSourceImpl.java:46)
# org.apache.tapestry.corelib.components.Form.onAction(Form.java:362)

I view the Tapestry5.05 code.
I don't understand why try to split component's id string by '.'
It seem that Tapestry5.05 organize all components into a tree.
I think all component's id is already identified by string.
Tapestry should find the component by whole string "a.b.c" directly, it not
necessary to track "a","b","c" netsted component.
-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12535559
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by Howard Lewis Ship <hl...@gmail.com>.
Here's the deal.

1) I always recommend that you provide an explicit t:id for form fields,
rather than let Tapestry assign the id.  In fact, I recommend assigning an
t:id to all non-trivial components.
2) Often, but far from always, you would end up using the same string in a
TextField for t:id and for the name of the property being edited (the
t:value parameter).
3) Thus the carrot: you can omit t:value when it will match t:id; the
TextField and similar components can default t:value based on t:id.
4) Don't fit that mold?  Use an explicit t:value.

So this is bad from one philosophy: that there should only be one way to
accomplish any one goal.

But I think it is good in terms of making things Just Work, which I find to
be very pragmatic.

On 9/7/07, smithfox <ss...@gmail.com> wrote:
>
>
> I do more test based you simple.
> Yes, a nested class also work.
>
> As you said: It's not tapestry issue.
>
> Your code is:
> [Page.java]
> private BznsPojo pojo= new BznsPojo();
>
> My code is:
> [Page.java]
> private BznsPojo pojo;
>
> @BeginRender
> void beginRender(){
>   pojo = createNewPojo();
> }
>
> private BznsPojo createNewPojo(){
>   BznsPojo pojo = new BznsPojo();
>   Product product = new Product();
>   pojo.setProduct(product);
>   return pojo;
> }
>
>
> So the problem is caused by lifecycle of pojo:
> I guess that  pojo's nested field object have already referenced by page
> template before BeginRender( and SteupRender) event.
>
> So I change the code:
>
> My code is:
> [Page.java]
> @Retain
> private BznsPojo pojo;
>
> .....
>
>
> OK, It work.
>
> Thank for Filip's help.
>
>
>
>
> Filip S. Adamsen-2 wrote:
> >
> > I did a test, and it worked.
> >
> > Can you show me more of your source code? It might be some non-Tapestry
> > issue.
> >
> > smithfox skrev:
> >> Thank your very much.
> >> I test your code. It can pass.
> >>
> >> But my case is different with yours.
> >> Your business object is a simple POJO class.
> >> But if you add another business class to the simple POJO class as a
> >> field,
> >> the tapestry doesn't recognise it.
> >>
> >> "sale.date" can pass,
> >> But "sale.product.price" can't pass.
> >>
> >> You can do a test.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12555589
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50


Creator Apache Tapestry and Apache HiveMind

Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
I do more test based you simple.
Yes, a nested class also work.

As you said: It's not tapestry issue.

Your code is:
[Page.java]
private BznsPojo pojo= new BznsPojo();

My code is:
[Page.java]
private BznsPojo pojo;

@BeginRender
void beginRender(){
  pojo = createNewPojo();
}

private BznsPojo createNewPojo(){
  BznsPojo pojo = new BznsPojo();
  Product product = new Product();
  pojo.setProduct(product);
  return pojo;
}


So the problem is caused by lifecycle of pojo:
I guess that  pojo's nested field object have already referenced by page
template before BeginRender( and SteupRender) event.

So I change the code:

My code is:
[Page.java]
@Retain
private BznsPojo pojo;

.....


OK, It work.

Thank for Filip's help. 




Filip S. Adamsen-2 wrote:
> 
> I did a test, and it worked.
> 
> Can you show me more of your source code? It might be some non-Tapestry 
> issue.
> 
> smithfox skrev:
>> Thank your very much.
>> I test your code. It can pass.
>> 
>> But my case is different with yours.
>> Your business object is a simple POJO class.
>> But if you add another business class to the simple POJO class as a
>> field,
>> the tapestry doesn't recognise it.
>> 
>> "sale.date" can pass, 
>> But "sale.product.price" can't pass.
>> 
>> You can do a test.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12555589
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
I did a test, and it worked.

Can you show me more of your source code? It might be some non-Tapestry 
issue.

smithfox skrev:
> Thank your very much.
> I test your code. It can pass.
> 
> But my case is different with yours.
> Your business object is a simple POJO class.
> But if you add another business class to the simple POJO class as a field,
> the tapestry doesn't recognise it.
> 
> "sale.date" can pass, 
> But "sale.product.price" can't pass.
> 
> You can do a test.

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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
Thank your very much.
I test your code. It can pass.

But my case is different with yours.
Your business object is a simple POJO class.
But if you add another business class to the simple POJO class as a field,
the tapestry doesn't recognise it.

"sale.date" can pass, 
But "sale.product.price" can't pass.

You can do a test.


Filip S. Adamsen-2 wrote:
> 
> Login.java:
> 
> public class Login {
> 
>    // Credentials is a simple POJO with two
>    // properties, username and password
>    private Credentials credentials = new Credentials();
> 
>    /* lots of other stuff */
> }
> 
> Login.html:
> 
> [header stuff]
>    <t:form>
>      <t:errors/>
> 
>      <t:textfield t:id="username" t:value="credentials.username"/>
>      <t:passwordfield t:id="password" t:value="credentials.password"/>
>      <input type="submit" value="Login"/>
>    </t:form>
> [footer stuff]
> 
> Renders as (minus the validation stuff etc.):
> 
> [header stuff]
>    <form>
>      <input id="username" name="username" type="text" value="">
>      <input id="password" name="password" type="password" value="">
>      <input type="submit" value="Login">
>    </form>
> [footer stuff]
> 
> The important thing is that Tapestry knows that the field username is 
> connected to the property credentials.username, and that the field 
> password is connected to the property credentials.password. But you 
> don't have to worry about that.
> 
> smithfox skrev:
>> I'm sure that I have getter and setter for price.
>> Could you show me your code. 
>> Thanks
>> 
>> 
>> Filip S. Adamsen-2 wrote:
>>> Make sure you've declared a getter and setter for price in your Product 
>>> class. The output you're seeing is expected and works for me in a 
>>> similar case.
>>>
>>> smithfox skrev:
>>>> Yes, I tried earlier
>>>>
>>>> <form t:type="form">
>>>> <input t:type="TextField" t:value="sale.product.price"/>
>>>> <input type="submit" value="submit"/>
>>>> </form>
>>>>
>>>> After render, the html is :
>>>> <input id="textfield" name="textfield" type="text" value="12"> 
>>>>
>>>> Obviously, when i submit, occur exception beacuse my page class has no
>>>> textfield field.
>>>>
>>>>
>>>>
>>>> Filip S. Adamsen-2 wrote:
>>>>> Yeah, then you definitely need to set the VALUE to sale.product.price, 
>>>>> not the id. Just listen to Nick, he knows what he's talking about. : )
>>>>>
>>>>> smithfox skrev:
>>>>>> It's a edit form.
>>>>>>
>>>>>> Nick Westgate wrote:
>>>>>>> Why are you binding the id to that? Don't you mean
>>>>>>> t:value="sale.product.price"?
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Nick.
>>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>
>>>
>>>
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12554977
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Login.java:

public class Login {

   // Credentials is a simple POJO with two
   // properties, username and password
   private Credentials credentials = new Credentials();

   /* lots of other stuff */
}

Login.html:

[header stuff]
   <t:form>
     <t:errors/>

     <t:textfield t:id="username" t:value="credentials.username"/>
     <t:passwordfield t:id="password" t:value="credentials.password"/>
     <input type="submit" value="Login"/>
   </t:form>
[footer stuff]

Renders as (minus the validation stuff etc.):

[header stuff]
   <form>
     <input id="username" name="username" type="text" value="">
     <input id="password" name="password" type="password" value="">
     <input type="submit" value="Login">
   </form>
[footer stuff]

The important thing is that Tapestry knows that the field username is 
connected to the property credentials.username, and that the field 
password is connected to the property credentials.password. But you 
don't have to worry about that.

smithfox skrev:
> I'm sure that I have getter and setter for price.
> Could you show me your code. 
> Thanks
> 
> 
> Filip S. Adamsen-2 wrote:
>> Make sure you've declared a getter and setter for price in your Product 
>> class. The output you're seeing is expected and works for me in a 
>> similar case.
>>
>> smithfox skrev:
>>> Yes, I tried earlier
>>>
>>> <form t:type="form">
>>> <input t:type="TextField" t:value="sale.product.price"/>
>>> <input type="submit" value="submit"/>
>>> </form>
>>>
>>> After render, the html is :
>>> <input id="textfield" name="textfield" type="text" value="12"> 
>>>
>>> Obviously, when i submit, occur exception beacuse my page class has no
>>> textfield field.
>>>
>>>
>>>
>>> Filip S. Adamsen-2 wrote:
>>>> Yeah, then you definitely need to set the VALUE to sale.product.price, 
>>>> not the id. Just listen to Nick, he knows what he's talking about. : )
>>>>
>>>> smithfox skrev:
>>>>> It's a edit form.
>>>>>
>>>>> Nick Westgate wrote:
>>>>>> Why are you binding the id to that? Don't you mean
>>>>>> t:value="sale.product.price"?
>>>>>>
>>>>>> Cheers,
>>>>>> Nick.
>>>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>>
>>
> 

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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
I'm sure that I have getter and setter for price.
Could you show me your code. 
Thanks


Filip S. Adamsen-2 wrote:
> 
> Make sure you've declared a getter and setter for price in your Product 
> class. The output you're seeing is expected and works for me in a 
> similar case.
> 
> smithfox skrev:
>> Yes, I tried earlier
>> 
>> <form t:type="form">
>> <input t:type="TextField" t:value="sale.product.price"/>
>> <input type="submit" value="submit"/>
>> </form>
>> 
>> After render, the html is :
>> <input id="textfield" name="textfield" type="text" value="12"> 
>> 
>> Obviously, when i submit, occur exception beacuse my page class has no
>> textfield field.
>> 
>> 
>> 
>> Filip S. Adamsen-2 wrote:
>>> Yeah, then you definitely need to set the VALUE to sale.product.price, 
>>> not the id. Just listen to Nick, he knows what he's talking about. : )
>>>
>>> smithfox skrev:
>>>> It's a edit form.
>>>>
>>>> Nick Westgate wrote:
>>>>> Why are you binding the id to that? Don't you mean
>>>>> t:value="sale.product.price"?
>>>>>
>>>>> Cheers,
>>>>> Nick.
>>>>>
>>> ---------------------------------------------------------------------
>>> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12554435
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Make sure you've declared a getter and setter for price in your Product 
class. The output you're seeing is expected and works for me in a 
similar case.

smithfox skrev:
> Yes, I tried earlier
> 
> <form t:type="form">
> <input t:type="TextField" t:value="sale.product.price"/>
> <input type="submit" value="submit"/>
> </form>
> 
> After render, the html is :
> <input id="textfield" name="textfield" type="text" value="12"> 
> 
> Obviously, when i submit, occur exception beacuse my page class has no
> textfield field.
> 
> 
> 
> Filip S. Adamsen-2 wrote:
>> Yeah, then you definitely need to set the VALUE to sale.product.price, 
>> not the id. Just listen to Nick, he knows what he's talking about. : )
>>
>> smithfox skrev:
>>> It's a edit form.
>>>
>>> Nick Westgate wrote:
>>>> Why are you binding the id to that? Don't you mean
>>>> t:value="sale.product.price"?
>>>>
>>>> Cheers,
>>>> Nick.
>>>>
>> ---------------------------------------------------------------------
>> 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: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
Yes, I tried earlier

<form t:type="form">
<input t:type="TextField" t:value="sale.product.price"/>
<input type="submit" value="submit"/>
</form>

After render, the html is :
<input id="textfield" name="textfield" type="text" value="12"> 

Obviously, when i submit, occur exception beacuse my page class has no
textfield field.



Filip S. Adamsen-2 wrote:
> 
> Yeah, then you definitely need to set the VALUE to sale.product.price, 
> not the id. Just listen to Nick, he knows what he's talking about. : )
> 
> smithfox skrev:
>> It's a edit form.
>> 
>> Nick Westgate wrote:
>>> Why are you binding the id to that? Don't you mean
>>> t:value="sale.product.price"?
>>>
>>> Cheers,
>>> Nick.
>>>
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12536761
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Yeah, then you definitely need to set the VALUE to sale.product.price, 
not the id. Just listen to Nick, he knows what he's talking about. : )

smithfox skrev:
> It's a edit form.
> 
> Nick Westgate wrote:
>> Why are you binding the id to that? Don't you mean
>> t:value="sale.product.price"?
>>
>> Cheers,
>> Nick.
>>
> 

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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by smithfox <ss...@gmail.com>.
It's a edit form.

Nick Westgate wrote:
> 
> Why are you binding the id to that? Don't you mean
> t:value="sale.product.price"?
> 
> Cheers,
> Nick.
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-bind-composite-class%27-field%28like-sale.product.price%29-in-page-template-tf4395512.html#a12536209
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: How to bind composite class' field(like sale.product.price) in page template

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Why are you binding the id to that? Don't you mean t:value="sale.product.price"?

Cheers,
Nick.


smithfox wrote:
> I wrote:
> 
> <input t:type="TextField" t:id="sale.product.price"/>
> 
> class Sale{ 
>   public Product getProduct(){return this.product};
>   public void setProduct(Product product){this.product=product};
> }
> 
> class Product{  private double price;}
> 
> but can't pass.

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