-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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();
}
}
}
Assume SpecialComposer
is the class you want to call a different doAfterCompose ()
. There are several ways:
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());
}
}
public class SpecialComposer extends GenericForwardComposer {
//if this composer doesn't need those methods in CommonComposer
}
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());
}
}
Asked: 2021-05-11 20:13:20 +0800
Seen: 6 times
Last updated: May 12 '21