0

How to differentiate doaftercompose for that already extend GenericForwardComposer

asked 2021-05-11 20:13:20 +0800

soldier gravatar image soldier
1

updated 2021-05-12 09:08:41 +0800

cor3000 gravatar image cor3000
5935 2 7
ZK Team

So here previously, I have a class commonComposer and all my other class related to .zul file will extends this CommonComposer. Now I want to differentiate for specific .zul file will call function doAfterCompose like this:

@Override
public void doAfterCompose(Component comp) throws Exception {
    // TODO Auto-generated method stub
    super.doAfterCompose(comp);
}

my question almost similar like this answer in (How to execute block of code inside doaftercompose). However the implementation will be different cause I have already extends GenericForwardComposer. look code below. Please help me and assist me step by step to solve this. Thank you so much

public class CommonComposer extends GenericForwardComposer{
private static final long serialVersionUID = 6848767592732520915L;
private ActivityService activityService;
private User admin;
String adminLoggedIn = "Admin";

@Override
public void doAfterCompose(Component comp) throws Exception {
    // TODO Auto-generated method stub
    super.doAfterCompose(comp);
    activityService = (ActivityService) SpringUtil.getBean("activityService");
    admin = ContextHelper.getUser();
    adminLoggedIn = admin.getLoginId();

}

protected void navigateTo(String url, Map<String,Object> args, Component currentComponent){
    Component parent = currentComponent.getParent();
    currentComponent.detach();
    Executions.createComponents(url, parent, args);
    try {
//          System.out.println("admin"+ admin.getLoginId());
            activityService.createActivity(adminLoggedIn, adminLoggedIn,
                    null, "url: "+ url, null, null, null,
                    "CLICK", adminLoggedIn, null);
        } catch (NullPointerException | BusinessException e) {
            e.printStackTrace();
        }
    }
}
delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2021-05-12 10:34:43 +0800

hawk gravatar image hawk
2837 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2021-05-12 10:35:45 +0800

Assume SpecialComposer is the class you want to call a different doAfterCompose (). There are several ways:

Provide another method in parent class

public class CommonComposer extends GenericForwardComposer {

    public void defaultDoAfterComposer(Component comp) throws Exception {
        super.doAfterCompose(comp);
        System.out.println("alternative doaftercompose in " + this.getClass());
    }
}
public class SpecialComposer3 extends CommonComposer {

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.defaultDoAfterComposer(comp);
        System.out.println("doaftercompose in" + this.getClass());
    }
}

Extend GenericForwardComposer

public class SpecialComposer extends GenericForwardComposer {
    //if this composer doesn't need those methods in CommonComposer
}

Override the logic

public class SpecialComposer2 extends CommonComposer {

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        /* make activityService, admin, adminLoggedIn protected and override them here
         */
        System.out.println("doaftercompose in" + this.getClass());
    }
}
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: 2021-05-11 20:13:20 +0800

Seen: 6 times

Last updated: May 12

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