You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Boris Horvat <ho...@gmail.com> on 2014/04/26 17:36:26 UTC

Component ID

Hi,

I believe that I am doing something wrong but just wanted to confirm if
that is the case.

I have a component that I pass in the loop.

<t:Edit t:id="image" t:value="projectImage" t:context="currentProject"
edittype="imageupload" />

Inside that I component I have a a zone and ajaxUpload component (from
jquery but I dont think that plays any role here)

Now the idea is that once someone uploads an image we refresh the zone,
however I cant seem to trigger the refresh for the correct zone due to the
loop iteration. I have tried to create a property

    @Persist
    @Property(read = false)
    private String zoneImageUploadId;

    public String getZoneImageUploadId() {
        if (zoneImageUploadId == null)
            zoneImageUploadId =
javascriptSupport.allocateClientId(resources);
        return zoneImageUploadId;
    }

however it is as if the Persist anotation forces the zoneImageUploadId to
be shared in all of the loop iterations so they all get the same (first)
client id.

Any idea if I am doing something wrong or is this expected behaviour and I
should pass the zone id as a parameter from outside of the component?

Cheers

-- 
Sincerely
*Boris Horvat*

Re: Component ID

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 26 Apr 2014 15:29:39 -0300, Boris Horvat  
<ho...@gmail.com> wrote:

> I guess in my mind it is like creating 5 instance of the same component  
> and then each instance will have their own version of the property that  
> is
> persisted. But this appears to be my wrong interpretation

Yeah, that's a wrong interpretation. There's one component instance for  
each of its declaration, not matter how many times it is rendered.

> This is implemented and I am happy to say that it works and I am glad to
> hear that it is a correct approach.

:)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Component ID

Posted by Boris Horvat <ho...@gmail.com>.
On Sat, Apr 26, 2014 at 8:25 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Sat, 26 Apr 2014 13:33:03 -0300, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  But is it expected for the things that are @Persist-ed to be shared in
>> each iteration?
>>
>
> What do you mean by shared? If you overwrite a @Persist'ed value, anything
> that reads it later, regardless of being in inside a loop or not, will read
> the same value. So, in your code as posted in this thread, when an event
> occurrs, you'll always get the value of the last item in the iteration.
> @Persist is basically reading and writing to an HttpSession attributed
> named [fully qualified page name]:[field name], when it's in a page, or
> [fully qualified page name].[full component id]:[field name].


I guess in my mind it is like creating 5 instance of the same component and
then each instance will have their own version of the property that is
persisted. But this appears to be my wrong interpretation



>
>
>  I will try to pass the client zone id to the context and to use it back
>> to refresh the proper zone (I did come up with same idea but I was thinking
>> that it is wrong path to follow)
>>
>
> Actually, that's the correct approach. It works in every situation and no
> session persistence needed. Win-win situation. :)


This is implemented and I am happy to say that it works and I am glad to
hear that it is a correct approach.

Thanks


>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: Component ID

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 26 Apr 2014 13:33:03 -0300, Boris Horvat  
<ho...@gmail.com> wrote:

> But is it expected for the things that are @Persist-ed to be shared in  
> each iteration?

What do you mean by shared? If you overwrite a @Persist'ed value, anything  
that reads it later, regardless of being in inside a loop or not, will  
read the same value. So, in your code as posted in this thread, when an  
event occurrs, you'll always get the value of the last item in the  
iteration. @Persist is basically reading and writing to an HttpSession  
attributed named [fully qualified page name]:[field name], when it's in a  
page, or [fully qualified page name].[full component id]:[field name].

> I will try to pass the client zone id to the context and to use it back  
> to refresh the proper zone (I did come up with same idea but I was  
> thinking
> that it is wrong path to follow)

Actually, that's the correct approach. It works in every situation and no  
session persistence needed. Win-win situation. :)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Component ID

Posted by Boris Horvat <ho...@gmail.com>.
But is it expected for the things that are @Persist-ed to be shared in each
iteration?

I will try to pass the client zone id to the context and to use it back to
refresh the proper zone (I did come up with same idea but I was thinking
that it is wrong path to follow)


On Sat, Apr 26, 2014 at 6:29 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Sat, 26 Apr 2014 12:36:26 -0300, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  Hi,
>>
>
> Hi!
>
>
>
>> I believe that I am doing something wrong but just wanted to confirm if
>> that is the case.
>>
>> I have a component that I pass in the loop.
>>
>> <t:Edit t:id="image" t:value="projectImage" t:context="currentProject"
>> edittype="imageupload" />
>>
>
> So, very important, you have a single component instance which is rendered
> many times.
>
>
>  Now the idea is that once someone uploads an image we refresh the zone,
>> however I cant seem to trigger the refresh for the correct zone due to the
>> loop iteration. I have tried to create a property
>>
>>     @Persist
>>     @Property(read = false)
>>     private String zoneImageUploadId;
>>
>>     public String getZoneImageUploadId() {
>>         if (zoneImageUploadId == null)
>>             zoneImageUploadId =
>> javascriptSupport.allocateClientId(resources);
>>         return zoneImageUploadId;
>>     }
>>
>
> I see no point in persisting the zoneImageUploadId. Instead, you should
> pass it context of the event that uploads the zone.
>
> In addition, what you're calling component id isn't the component id,
> t:id, but the HTML, client-side id, and they're different things that may
> or may not have the same value.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: Component ID

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 26 Apr 2014 12:36:26 -0300, Boris Horvat  
<ho...@gmail.com> wrote:

> Hi,

Hi!

>
> I believe that I am doing something wrong but just wanted to confirm if
> that is the case.
>
> I have a component that I pass in the loop.
>
> <t:Edit t:id="image" t:value="projectImage" t:context="currentProject"
> edittype="imageupload" />

So, very important, you have a single component instance which is rendered  
many times.

> Now the idea is that once someone uploads an image we refresh the zone,
> however I cant seem to trigger the refresh for the correct zone due to  
> the
> loop iteration. I have tried to create a property
>
>     @Persist
>     @Property(read = false)
>     private String zoneImageUploadId;
>
>     public String getZoneImageUploadId() {
>         if (zoneImageUploadId == null)
>             zoneImageUploadId =
> javascriptSupport.allocateClientId(resources);
>         return zoneImageUploadId;
>     }

I see no point in persisting the zoneImageUploadId. Instead, you should  
pass it context of the event that uploads the zone.

In addition, what you're calling component id isn't the component id,  
t:id, but the HTML, client-side id, and they're different things that may  
or may not have the same value.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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