You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by holod <se...@gmail.com> on 2008/07/31 10:16:15 UTC

And I will explain why.
If I make any mistakes, please, tell me.
This is my struts2 tag:
<s:a id="AncorId" 
       showLoadingText="false" 
       targets="%{'linkattachedMainDocRow' + #document.count}"
       theme="ajax" 
       href="%{#deleteDocumentAction}"
       notifyTopics="/afterDeleteLaw">
       Click me!
</s:a>
this is my JS code:
dojo.event.topic.subscribe("/afterDeleteLaw", _listeners, "test1");
var _listeners = {
	test1: function(sourceId){
                 alert("sourceId");
        }
};

Do you know what will happen? I'll tell you. test(sourceId) will be invoked
twice.
The first time sourceId = id of dojo anchor widget (AncorId)
The second time sourceId = response text (text which my action returned).

This is amazing logic:
The first time you get widget, that sends request, the second time you get
response and you don't have any opportunity to determine, which anchor
recieved this response!
 
Imagine such situation:
Inside <s:iterator> you make several <s:a> widgets, you generate unique
<s:url> for them and id attribute. 
User starts to click on widgets, they all start to send requests and receive
responses. As you know, JS in not thread safe, it means in a few seconds you
get terrible mix of widgets and responses inside subscribed topic. 

I've spent three days trying to solve it, the right solution is: do not use
dojo anchor tag, use jQuery or your own custom ajax functions.

Please, take into consideration, it's extremely hard to get on with
listeners, I was lucky and got an idea of using listeners inside
google.code. I still don't understand how it works.

As I understand, the idea of ajax tags is to simplyfy the work, not to make
it as complicated, as possible.

RFC.

-- 
View this message in context: http://www.nabble.com/%3Cs%3Aa-dojo-anchor%2C-seems-like-better-not-to-use-it-and-realize-it-yourself-tp18749842p18749842.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Posted by holod <se...@gmail.com>.
Dave thanks again for your help. I will watch these three videos. 
Early I've used Google Web Toolkit for making complicated WEB UI
My brain will blow up If there would appear another version of docs for
struts2. 
I've googled all around, but I didn't find fact about two invocations.



newton.dave wrote:
> 
> Another option is to read the documentation, which indicates that the
> JavaScript function will be called twice (although it's better-stated in
> the 2.1 docs), once getting the id, and then again on success or error,
> with the HTML result.
> 
> http://struts.apache.org/2.0.11/docs/ajax-tags.html#AjaxTags-anchorTag
> 
> When you specify a handler you can use closure to include the ID of the
> widget you're creating the handler for, but that's a JS issue, not Struts.
> JS has a few major warts (yeah, thanks for binding "this" all goofy, JS)
> but it's very powerful when used with skill.
> 
> If you're interested in programming JS I'd recommend the Crockford videos.
> Well worth the time, and it'll improve your programming in other languages
> as well.
> 
> Dave
> 
> 
> --- On Thu, 7/31/08, holod <se...@gmail.com> wrote:
> 
>> From: holod <se...@gmail.com>
>> Subject: <s:a dojo-anchor, seems like better not to use it and realize it
>> yourself
>> To: user@struts.apache.org
>> Date: Thursday, July 31, 2008, 4:16 AM
>> And I will explain why.
>> If I make any mistakes, please, tell me.
>> This is my struts2 tag:
>> <s:a id="AncorId" 
>>        showLoadingText="false" 
>>        targets="%{'linkattachedMainDocRow' +
>> #document.count}"
>>        theme="ajax" 
>>        href="%{#deleteDocumentAction}"
>>        notifyTopics="/afterDeleteLaw">
>>        Click me!
>> </s:a>
>> this is my JS code:
>> dojo.event.topic.subscribe("/afterDeleteLaw",
>> _listeners, "test1");
>> var _listeners = {
>> 	test1: function(sourceId){
>>                  alert("sourceId");
>>         }
>> };
>> 
>> Do you know what will happen? I'll tell you.
>> test(sourceId) will be invoked
>> twice.
>> The first time sourceId = id of dojo anchor widget
>> (AncorId)
>> The second time sourceId = response text (text which my
>> action returned).
>> 
>> This is amazing logic:
>> The first time you get widget, that sends request, the
>> second time you get
>> response and you don't have any opportunity to
>> determine, which anchor
>> recieved this response!
>>  
>> Imagine such situation:
>> Inside <s:iterator> you make several <s:a>
>> widgets, you generate unique
>> <s:url> for them and id attribute. 
>> User starts to click on widgets, they all start to send
>> requests and receive
>> responses. As you know, JS in not thread safe, it means in
>> a few seconds you
>> get terrible mix of widgets and responses inside subscribed
>> topic. 
>> 
>> I've spent three days trying to solve it, the right
>> solution is: do not use
>> dojo anchor tag, use jQuery or your own custom ajax
>> functions.
>> 
>> Please, take into consideration, it's extremely hard to
>> get on with
>> listeners, I was lucky and got an idea of using listeners
>> inside
>> google.code. I still don't understand how it works.
>> 
>> As I understand, the idea of ajax tags is to simplyfy the
>> work, not to make
>> it as complicated, as possible.
>> 
>> RFC.
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/%3Cs%3Aa-dojo-anchor%2C-seems-like-better-not-to-use-it-and-realize-it-yourself-tp18749842p18749842.html
>> Sent from the Struts - User mailing list archive at
>> Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/%3Cs%3Aa-dojo-anchor%2C-seems-like-better-not-to-use-it-and-realize-it-yourself-tp18749842p18756299.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Posted by Dave Newton <ne...@yahoo.com>.
Another option is to read the documentation, which indicates that the JavaScript function will be called twice (although it's better-stated in the 2.1 docs), once getting the id, and then again on success or error, with the HTML result.

http://struts.apache.org/2.0.11/docs/ajax-tags.html#AjaxTags-anchorTag

When you specify a handler you can use closure to include the ID of the widget you're creating the handler for, but that's a JS issue, not Struts. JS has a few major warts (yeah, thanks for binding "this" all goofy, JS) but it's very powerful when used with skill.

If you're interested in programming JS I'd recommend the Crockford videos. Well worth the time, and it'll improve your programming in other languages as well.

Dave


--- On Thu, 7/31/08, holod <se...@gmail.com> wrote:

> From: holod <se...@gmail.com>
> Subject: <s:a dojo-anchor, seems like better not to use it and realize it yourself
> To: user@struts.apache.org
> Date: Thursday, July 31, 2008, 4:16 AM
> And I will explain why.
> If I make any mistakes, please, tell me.
> This is my struts2 tag:
> <s:a id="AncorId" 
>        showLoadingText="false" 
>        targets="%{'linkattachedMainDocRow' +
> #document.count}"
>        theme="ajax" 
>        href="%{#deleteDocumentAction}"
>        notifyTopics="/afterDeleteLaw">
>        Click me!
> </s:a>
> this is my JS code:
> dojo.event.topic.subscribe("/afterDeleteLaw",
> _listeners, "test1");
> var _listeners = {
> 	test1: function(sourceId){
>                  alert("sourceId");
>         }
> };
> 
> Do you know what will happen? I'll tell you.
> test(sourceId) will be invoked
> twice.
> The first time sourceId = id of dojo anchor widget
> (AncorId)
> The second time sourceId = response text (text which my
> action returned).
> 
> This is amazing logic:
> The first time you get widget, that sends request, the
> second time you get
> response and you don't have any opportunity to
> determine, which anchor
> recieved this response!
>  
> Imagine such situation:
> Inside <s:iterator> you make several <s:a>
> widgets, you generate unique
> <s:url> for them and id attribute. 
> User starts to click on widgets, they all start to send
> requests and receive
> responses. As you know, JS in not thread safe, it means in
> a few seconds you
> get terrible mix of widgets and responses inside subscribed
> topic. 
> 
> I've spent three days trying to solve it, the right
> solution is: do not use
> dojo anchor tag, use jQuery or your own custom ajax
> functions.
> 
> Please, take into consideration, it's extremely hard to
> get on with
> listeners, I was lucky and got an idea of using listeners
> inside
> google.code. I still don't understand how it works.
> 
> As I understand, the idea of ajax tags is to simplyfy the
> work, not to make
> it as complicated, as possible.
> 
> RFC.
> 
> -- 
> View this message in context:
> http://www.nabble.com/%3Cs%3Aa-dojo-anchor%2C-seems-like-better-not-to-use-it-and-realize-it-yourself-tp18749842p18749842.html
> Sent from the Struts - User mailing list archive at
> Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org