0

The lifecycle of controller ?

asked 2009-07-27 06:42:29 +0800

jimmytan gravatar image jimmytan
60 2

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.

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-07-27 13:27:03 +0800

jtoupin gravatar image jtoupin
156

The scope of the composers are the window components I believe. The same instance of the composer is used until the window component is destroyed.

link publish delete flag offensive edit

answered 2009-07-27 23:19:16 +0800

robertpic71 gravatar image robertpic71
1275 1

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

link publish delete flag offensive edit

answered 2009-07-28 02:27:15 +0800

jimmytan gravatar image jimmytan
60 2

very useful, thanks.

link publish delete flag offensive edit

answered 2012-04-09 07:12:36 +0800

tsinglongwu gravatar image tsinglongwu
30 2

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

link publish delete flag offensive edit

answered 2012-04-10 08:20:52 +0800

Shanks gravatar image Shanks
12

Hi,

have you checked that your controller (object) id stays the same? I would suspect JMS to create new instances, which would explain the null values.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-07-27 06:42:29 +0800

Seen: 722 times

Last updated: Apr 10 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More