linwei
Nov 21st, 2004, 01:52 PM
Hi,
I encountered a problem on pulishing ApplicaitionEvent from "application-context" to "commands-context". I have a button, "exportTabletCommand", defined in "commands-context". This button is disabled in intialization, and depends on the database connection status to enable it. The db connection operation is in a wizard defined in "application-context", and the wizard's "onFinish" will pulish an ApplicatinEvent:
protected boolean onFinish(){
wizardForm.commit();
try{
//Connect to DB
...............
DatabaseConnectionEvent evt = new DatabaseConnectionEvent(this);
evt.setIpDbConnected(true);
getApplicationContext().publishEvent(evt);
.....
return true;
}
( My "DatabaseConnectionEvent" extends from ApplicationEvent ).
The "exportTabletCommand" is listening on ApplicationEvent to set itself enabled/disabled:
public class ExportTabletCommand extends TargetableActionCommand implements ApplicationListener {
public void onApplicationEvent(ApplicationEvent event) {
if( event instanceof DatabaseConnectionEvent){
DatabaseConnectionEvent dbevent = (DatabaseConnectionEvent)event;
if( dbevent.isIpDbConnected() ){
this.setEnabled(true);
}
.......................
}
I assume that all the beans which implement "ApplicationListener" could capture the ApplicationEvent, whether the beans are defined in "application-context" or "commands-context". But I found that, the " ExportTabletCommand" listener can't capture any ApplicationEvent( it is defined in "commands-context"). But, when I tried to move its definition to "application-context", it can capture ApplicaitonEvent!
I am wondering: could the ApplicationEvent be published from beans defined in "application-context" to the beans defined in "commands-context"? In my case, I do believe this is neccessary. Or, is there any better way to do it?
Thanks a lot in advance.
I encountered a problem on pulishing ApplicaitionEvent from "application-context" to "commands-context". I have a button, "exportTabletCommand", defined in "commands-context". This button is disabled in intialization, and depends on the database connection status to enable it. The db connection operation is in a wizard defined in "application-context", and the wizard's "onFinish" will pulish an ApplicatinEvent:
protected boolean onFinish(){
wizardForm.commit();
try{
//Connect to DB
...............
DatabaseConnectionEvent evt = new DatabaseConnectionEvent(this);
evt.setIpDbConnected(true);
getApplicationContext().publishEvent(evt);
.....
return true;
}
( My "DatabaseConnectionEvent" extends from ApplicationEvent ).
The "exportTabletCommand" is listening on ApplicationEvent to set itself enabled/disabled:
public class ExportTabletCommand extends TargetableActionCommand implements ApplicationListener {
public void onApplicationEvent(ApplicationEvent event) {
if( event instanceof DatabaseConnectionEvent){
DatabaseConnectionEvent dbevent = (DatabaseConnectionEvent)event;
if( dbevent.isIpDbConnected() ){
this.setEnabled(true);
}
.......................
}
I assume that all the beans which implement "ApplicationListener" could capture the ApplicationEvent, whether the beans are defined in "application-context" or "commands-context". But I found that, the " ExportTabletCommand" listener can't capture any ApplicationEvent( it is defined in "commands-context"). But, when I tried to move its definition to "application-context", it can capture ApplicaitonEvent!
I am wondering: could the ApplicationEvent be published from beans defined in "application-context" to the beans defined in "commands-context"? In my case, I do believe this is neccessary. Or, is there any better way to do it?
Thanks a lot in advance.