-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Would someone point me out that there are any documents mention about the life-cycle of controller. I'm using MVC pattern, and using controller for Window component. I'm wondering the life-cycle of an controller?
1) Will every click of Window component create an new controller instance, and release the instance once the process of the request completed?
2) In the ZK with Spring implementation, we do have annotation such as "idspace" to control the scope of new instance creation by Spring. I'm wondering that, if we are not using Spring, the life-cycle of controller would be ... ???
Thanks.
1.) As jtoupin say: the composer apply="com.xx.YourComposer" is created by the UI.
>> Will every click of Window component create an new controller instance, and release the instance once the process of the request completed?
The composer is created only when the windows is created. Clicks inside the window do not recreate the window and composer. Because it's AJAX not every action recreates the whole side.
2a)
Do get another scope for your composer you have to use any kind of EL's apply="${composer}". So i.e. Spring could controll the scope.
However, i.e. a scope "session" could make troubles because the controller/composer could not manage UI-Components from other desktops (i.e. the user create a second view with tabbrowsing).
2b)
There is a new way (in the zeta-templates) to annotate a controller for a zul-component. However this seems under construction (no official docs).
>> if we are not using Spring, the life-cycle of controller would be ... ???
If you not use Spring, @Controller, @Scope will not work.
Of course you could handle the scope yourself:
apply="${controller}"... // without any Spring/EJB.. resolver
Composer getController() {
// create your Composer or retrieve i.e from session
}
But i still prefer a spring-managed environment.
/Robert
Hi Robert,
I was blocked by a component lifecycle issue.
I want to upgrade Progressmeter infomation in backup.zul with processed message from JMS server. The page's bind class is following:
-------------------------------------------------
@Controller("backupDialogCtrl")
@Scope("prototype")
public class BackupCtrl extends GenericForwardComposer implements MessageListener {
private Window backupDialog;
private Textbox tDbIp, tDataPath, tAppVersion, tDescription;
private Label resultLabel;
private Progressmeter curr_pm;
public void doAfterCompose(Component comp) throws Exception{
super.doAfterCompose(comp);
}
public void onClick$backup() {
try {
resultLabel.setValue("Starting..."); // All the components is available.
desktop.enableServerPush(true);
DBBkRestI dbBkRest = DBBkRestImpl.getInstance();
dbBkRest.backupDB(); // Call JMS server method which will send message to consumers. The following method of onMessage() is the listener. It will accept and
// display all the messages.
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onMessage(Message message) { //It's extends javax.jms.MessageListener. It will be invoked whenever there are messages send from JMS server.
try {
if (message instanceof TextMessage) {
msgProcess = ((TextMessage)message).getText();
String[] msgs = msgProcess.split(",");
Executions.activate(desktop); // when jvm run at here, desktop is Null, include all of the components in the page.
curr_pm.setValue(Integer.parseInt(msgs[0])); // curr_pm is null too.
resultLabel.setValue(msgs[1]); // resultLabel is null here.
Executions.deactivate(desktop);
} else {
System.out.println("Message of wrong type: "
+ message.getClass().getName());
}
} catch (JMSException e) {
... ...
} catch (Throwable t) {
... ...
} finally {
... ...
}
}
}
-----------------------------------
When the onMessage() is invoked, all the components is Null(include the window of backupDialog). How can I use the components in the method of onMessage().
Thank you a lot!
Alex
Asked: 2009-07-27 06:42:29 +0800
Seen: 722 times
Last updated: Apr 10 '12