java - Publish an event using Struts 2 jQuery Plugin -


i want use publish/subscribe framework used internally strust2 jquery plugin.

the user can select account number list or type in textbox.

i want publish event when text box or select option changes. user can type textbox or select select box:

<s:textfield name="account"  onblur="$.publish('accountchanged',this,event)"/> <s:select name="accountlist" list="destinationaccounts"     onblur="$.publish('accountchanged',this,event)"/> 

below js:

$.subscribe('accountchanged', function(event, data) {     alert("new data is: " + data.value);     if ( event.target.id=='account') {         //do     } } 

here issues:

  1. the data.value works textbox, select box data.value undefined.
  2. i want know target received event. event.target.id not working! think event object not jquery event object?

i reviewed sample showcase application, not find any.

am calling $.publish method correctly? there better ways?

if subscribe topics keep topic name unique each tag allows separate handlers tag. new event created each time publish topic in onblur event. textfield handler topic works described. select tag doesn't work because wrong parameter passed data. example of working code

<s:textfield name="account"  onblur="$(this).publish('accountchanged', this, event)"/> <s:select name="accountlist" list="{'list1', 'list2','list3'}" onblur="$(this).publish('accountlistchanged', this, event)"/> <script type="text/javascript">   $.subscribe('accountchanged', function(event, data) {     alert("accountchanged: " + data.value);   });   $.subscribe('accountlistchanged', function(event, data) {     alert("accountlistchanged: " + data.parentelement.value);   }); </script>  

as can see data.value undefined because data.parentelement.value should used. event.target.id not working because event.originalevent.target.id should used. event object jquery event, originalevent dhtml object blur.

i don't know requirements, if need subscribe/publish events or use original event handlers, can't better in situation.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -