Thursday, September 20, 2007

Map representation in Spring & Javascript


<bean id="action2Dashboard" class="java.util.HashMap" singleton="true">
   <constructor-arg>
     <map>
       <entry key="/admin/license/installLicense.action">
       <value>system:administration_setupsupport.3</value>
       </entry>
       <entry key="/admin/agent/listAgents.action">
       <value>system:administration_agents.5</value>
     </entry>
     </map>
   </constructor-arg>
</bean>


self.dashboards = {
  "/admin/license/installLicense.action" : "system:administration_setupsupport.3",
  "/admin/agent/listAgents.action" : "system:administration_agents.5"
}

var dashboard = dashboards["/admin/licnese/installLicense.action"];

Thursday, September 13, 2007

Publish/Subscribe



NotificationService {
publish(topic, payload);
subscribe(topic, listener);
}

Internally, each topic maintain a set of listener; Alternatively, topic is not used, uses more specific method such as addMouseClickListener(...) to specify it implicitly.

Callee subscribe/unsubscribe the listeners to interesting topic; When something happend (e.g, UI interaction, object added, removed or modified), event is fired, (The event carries all the context information such as source object, action, context etc that listener need to know). publish() is invoked to notify listener.

Listener {
ObjectChanged(event);
}

Publish/Subscribe also known as Observer pattern. The Observer pattern defines an one-to-many dependency between a subject object and any number of observer objects so that when the subject object changes state, all its observer objects are notified and updated automatically.

In the diagram, we can see it doesn't pass an event/data/msg object though, one static reference to subject object is kept in concreteObserver to get the latest state information.

Tuesday, September 11, 2007

Javascript keyword "this"


function doSomething() {
this.style.color = '#cc0000';
}

In JavaScript this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of. hen we define our faithful function doSomething() in a page, its owner is the page, or rather, the window object (or global object) of JavaScript.

An onclick property, though, is owned by the HTML element it belongs to.

element.onclick = doSomething;

The function is copied in its entirety to the onclick property (which now becomes a method). So if the event handler is executed this refers to the HTML element and its color is changed.

However, if you use inline event registration

<element onclick="doSomething()">

you do not copy the function! Instead, you refer to it, the this keyword once again refers to the global window

Thursday, September 6, 2007

Javacript location reload

- To refresh current iframe


parent.frames['contentBox'].location.reload();

- To refresh current page

document.location.reload()

one good example, after ajax session timeout, invoking this will be taken to logon page.