1

Initiator is not called

asked 2014-10-29 08:58:56 +0800

viachris gravatar image viachris
27 5

updated 2014-10-29 09:59:44 +0800

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!

delete flag offensive retag edit

Comments

your welcome

chillworld ( 2014-10-29 10:03:20 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-10-29 09:05:41 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-10-29 09:56:04 +0800

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 {
    }
}

Note 1 :

Your @Init will not be interferred.

Note 2:

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>
link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2014-10-29 08:58:56 +0800

Seen: 23 times

Last updated: Oct 29 '14

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