-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
i want to restrict direct access to .zul pages by intercepting it via the Initiator.
But somehow the Initiator is not called before a page is loaded.
The Initiator:
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class UrlInterceptor implements Initiator {
@WireVariable
protected WegeUserContext userContext;
@Override
public void doInit(Page arg0, Map<String, Object> arg1) throws Exception {
if (!userContext.isAuthenticated()) {
Executions.getCurrent().sendRedirect("/index.zul");
}
}
}
zk.xml:
<zk>
<listener>
<listener-class>somePackage.WebbAppInitiator</listener-class>
<listener-class>somePackage.UrlInterceptor</listener-class>
</listener>
</zk>
Note: most ViewModels have a class annotated with @Init does this interfere with the Initiator?
Note 2: The WebAppInitiator works and thus it seems the general project config is correct.
EDIT: Somehow i can't answer chillworld, so i have to do it here:
Thanks for you answer!
But as far as i understand it, when i declare an Initiator as a listener class in the zk.xml it will be a system-level Inititator and automatically invoked before any page-inititation.
See the paragraph "System-level initiator: hxxp://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIPatterns/PageInitialization
EDIT2: Your second note was the answer, thank you chillworld!
Your initiator you must declare in your zuls (or in the master page of your zuls) :
<?init class="xx.xx.xx.UrlInterceptor"?>
example of mine initiator :
public class CatalogInitiator implements Initiator, InitiatorExt {
@Override
public void doInit(Page page, Map<String, Object> map) throws Exception {
if (someContition()) {
Executions.getCurrent().sendRedirect("/mainframe");
}
}
@Override
public void doAfterCompose(Page page, Component[] cmpnts) throws Exception {
}
@Override
public boolean doCatch(Throwable thrwbl) throws Exception {
return false;
}
@Override
public void doFinally() throws Exception {
}
}
Your @Init will not be interferred.
I think that you have to set your listeners like this :
<listener>
<listener-class>somePackage.WebbAppInitiator</listener-class>
</listener>
<listener>
<listener-class>somePackage.UrlInterceptor</listener-class>
</listener>
Asked: 2014-10-29 08:58:56 +0800
Seen: 23 times
Last updated: Oct 29 '14
wrong valueException come in front of modal popup [closed]
Use parameters in a conditional @command
Problems with multiple press and onCtrlKey
MVVM @save on the fly [closed]
Unable to activate destroyed desktop
org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException
How to put a image or Letter over image on a specific XY Coordinate
your welcome
chillworld ( 2014-10-29 10:03:20 +0800 )edit