0

Dynamically switch themes using cookie [closed]

asked 2013-04-24 10:46:13 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi

I am Dynamically switch themes using cookie as follows.

@AfterCompose
public void initSetup(@ContextParam(ContextType.VIEW) Component view) {


    Themes.setTheme(Executions.getCurrent(), Infrastructure.getUserLogin().getTheme());
    Executions.sendRedirect(null);


    final HashMap<String, Object> map = new HashMap<String, Object>();

    Selectors.wireComponents(view, this, false);

    /* get an instance of the searched CENTER layout area */
    Center c1 = borderLayout.getCenter();

    /* clear the center child */
    c1.getChildren().clear();

    map.put("centerArea", c1);
    /* Load the left navigation menu for patient cases */
    Executions.createComponents("userList.zul", c1, map);

}

But it becomes infinite loop. Because sendredirect again calling the same page. What is the alternate method to do this

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by Senthilchettyin
close date 2013-05-02 20:07:47

Comments

Any help please

Senthilchettyin ( 2013-04-25 16:35:06 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-04-29 03:36:11 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

updated 2013-04-29 10:50:22 +0800

You can try to change

Themes.setTheme(Executions.getCurrent(), Infrastructure.getUserLogin().getTheme());
Executions.sendRedirect(null);

to

String theme = Executions.getCurrent(), Infrastructure.getUserLogin().getTheme();
if (!theme.equals(Themes.getCurrentTheme())) {
    Themes.setTheme(Executions.getCurrent(), Infrastructure.getUserLogin().getTheme());
    Executions.sendRedirect(null);
}

then it should work

link publish delete flag offensive edit

Comments

Thanks. I will try. But sendredirect flickering the screen. You can the demo here

Senthilchettyin ( 2013-04-29 06:17:10 +0800 )edit

Yes, because the page is reloaded after it is loaded, as a workaround you can try two ways: 1, Make root component invisible (visible="false") and make it visible after the theme is correct. 2. Redirect to a page contains nothing for adjust theme then redirect to the page you want to show.

benbai ( 2013-04-29 11:03:12 +0800 )edit
1

answered 2013-04-30 18:59:59 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

updated 2013-05-01 11:04:59 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Thank you very benbai. Now i controlled the flickering problem as you said.

Just done the following to avoid such flickering.

  1. In the spring security, i changed the default-target-url="/index.zul".
  2. Actually index.zul is dummy zul without any component but has the VM as follows.
  3. Then from index.zul, i redirected to main.zul which is actual main file for the application.

    The ZUL File

    <zk> <window apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm')@init('zkexample.zkoss.IndexVM')"> </window> </zk>

    The Java Code

    import org.zkoss.bind.annotation.AfterCompose; import org.zkoss.bind.annotation.ContextParam; import org.zkoss.bind.annotation.ContextType; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zul.theme.Themes;

    public class IndexVM {
    
        @AfterCompose
        public void initSetup(@ContextParam(ContextType.VIEW) Component view) {
    
            String theme = FHSessionUtil.getCurrentUser().getTheme();
            if (!theme.equals(Themes.getCurrentTheme())) {
                Themes.setTheme(Executions.getCurrent(), FHSessionUtil
                        .getCurrentUser().getTheme());
            }
    
            Executions.sendRedirect("main.zul");
        }
    
    }
    
link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-04-24 10:46:13 +0800

Seen: 59 times

Last updated: May 01 '13

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