0

my login/index zul page is loading twice, where as i am only calling it once

asked 2013-03-19 12:25:04 +0800

qasibeat gravatar image qasibeat
12

I am using zk ce version 6.5 and i have a problem. My login/index pages is being loaded twice.

when i on logout button call this:

Executions.createComponents("login", center, null);

above page has two fields and i am using MVVM approach.

Now it loads fine, but as soon as i enter the username in the textbox or enter the password in textbox, page is automatically refreshed. I have checked in my code, i am not calling the above method anywhere else in a process here.

Please tell me why on textbox/password textbox i am getting this behaviour for the loginpage. once it's reloaded twice, it gets the username and takes me to home page. now i logout and same scenario.

for two times, i am getting call to this method, once is obvious, bacause on logout i called it, but on entering any text in textbox and removing the focus from it. then this method is again called.

@AfterCompose public void afterCompose(@ContextParam(ContextType.VIEW) Component view){ Selectors.wireComponents(view, this, false); }

I have inspected my code too, there is no event on any of the textfield.

login.zul

<zk> <window id="loginWin" border="none" width="100%" height="100%" apply="org.zkoss.bind.BindComposer" viewmodel="@id('vmc') @init('com.example.LoginViewModel')" validationmessages="@id('vmsgs')">

    <borderlayout>
        <west border="normal" size="70%" title="What Intelliops Do?">
            <div width="100%" height="100%">
                asdasd as asd a d asdasd a sd asd asasd asd d asdasd as
                d a d asdasd a sd asd asasd asd a d asdasd a sd asd
                asasd asd a d asdasd a sd asd asasd asd
            </div>
        </west>
        <east border="normal" size="30%" title="Login">
            <div width="100%" height="100%">
                <grid sizedByContent="true"
                    form="@id('lv') @load(vmc.userDto)
                   @save(vmc.userDto, before='loginButtonInvoke')
                   @validator('com.example.LoginValidator')">
                    <columns>
                        <column width="50%"></column>
                        <column width="50%"></column>
                    </columns>
                    <rows>
                        <row align="left" width="100%"
                            style="background:white;.row:hover{background-color: #fff};border:none">
                            <cell style="text-align:right">
                                User Name
                            </cell>
                            <cell>
                                <textbox id="userNameTextBox" type="text"
                                    value="@bind(lv.user.username)" maxlength="50" />
                                <image src="@load(vmsgs['userNameTextBoxError'])" width="12px"
                                    height="12px" tooltiptext="@load(vmsgs['userNameTextBox'])"></image>
                            </cell>
                        </row>
                        <row width="100%"
                            style="background:white;.row:hover{background-color: #fff};border:none">
                            <cell style="text-align:right">
                                Password
                            </cell>
                            <cell>
                                <textbox id="passwordTextBox" type="password"
                                    value="@bind(lv.user.password)" maxlength="20" />
                                <image src="@load(vmsgs['passwordTextBoxError'])" width="12px"
                                    height="12px" tooltiptext="@load(vmsgs['passwordTextBox'])" />
                            </cell>
                        </row>
                        <row width="100%"
                            style="background:white;.row:hover{background-color: #fff};border:none">
                            <cell style="text-align:right">
                                <button id="loginButton" label="Login"
                                    onClick="@command('loginButtonInvoke')" />
                            </cell>
                            <cell>
                                <label id="loginErrorLabel" style="color:red" />
                            </cell>
                        </row>
                        <row spans="2" width="100%"
                            style="background:white;.row:hover{background-color: #fff};border:none">
                            <cell colspan="2" style="text-align:right">
                                <a id="forgetPasswordLink">
                                    Forgot Password?
                                </a>
                            </cell>
                        </row>
                    </rows>
                </grid>
            </div>
        </east>
    </borderlayout>
</window>

</zk>

loginviewmode class

package com.example;

import org.apache.log4j.Logger; import org.zkoss.bind.annotation.AfterCompose; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ContextParam; import org.zkoss.bind.annotation.ContextType; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zkplus.spring.SpringUtil; import org.zkoss.zul.Label; import org.zkoss.zul.Textbox;

import com.example.UserDTO; import com.example.IUserService; import example.Pages; import example.TemplateUtil; import example.UserUtil;

public class LoginViewModel{

private Logger logger = Logger.getLogger(this.getClass().getName());

IUserService userService = (IUserService)SpringUtil.getBean("userService");

UserDTO userDto = new UserDTO();

private static final String USER_ROLES = "userRoles";
private static final String MASTER = "master";

@Wire("#userNameTextBox")
Textbox userNameTextBox;

@Wire("#passwordTextBox")
Textbox passwordTextBox;

@Wire("#loginErrorLabel")
Label loginErrorLabel;

@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view){
    Selectors.wireComponents(view, this, false);
 }

@Command("loginButtonInvoke")
public void loginButtonInvoke(){
    logger.info("LoginViewModel:afterCompose >>>>>>>>>>>>>>>");
    logger.info("loginButtonInvoke: " + userDto.getUserIntelliOps().getUsername() + " " + userDto.getUserIntelliOps().getPassword());
    userDto = userService.getUserAuthentication(userDto);



    if(userDto!=null){
        UserUtil.setSession(userDto);
        logger.info("loginButtonInvoke:userDto!=null ");
        /*List<ViewObjectOperation> list = userService.getAllOtherOperationsService().userAuthorizationMatrix(userDto.getUserIntelliOps().getRoles().get(0).toString());*/
        //List<ViewObjectOperation> list = userService.getAllOtherOperationsService().userAuthorizationMatrix(3+"");
        //logger.info("asdasdas   " + list.size());
        /*getUserAuthorizedMenu*/
        //TODO what is the following line doing here????
        userService.getUserAuthorizedMenu();

        TemplateUtil.loadContent(Pages.HOME_FILE,true);
    }else{
        if(userDto==null){
            userDto = new UserDTO();
        }
    loginErrorLabel.setValue("Invalid username or password.");
    }

}

public UserDTO getUserDto() {
    return userDto;
}

public void setUserDto(UserDTO userDto) {
    this.userDto = userDto;
}

}

TemplateUtil class to draw the pages

package com.example;

import org.apache.log4j.Logger;

import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Path; import org.zkoss.zul.A; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Button; import org.zkoss.zul.Center; import org.zkoss.zul.Include; import org.zkoss.zul.North;

public class TemplateUtil {

static Logger logger = Logger.getLogger(TemplateUtil.class.getName());

public static void loadContent(String contentPage, boolean isMenu) {


    logger.info("TemplateUtil: loadContent().......... ");

    Borderlayout mainlayout = (Borderlayout) Path.getComponent("/main/mainLayout");
    North topHeader = mainlayout.getNorth();

    topHeader.getFellow("menuDiv").setVisible(isMenu);

    //TODO remove the following logger

    if(isMenu==true ){
        anchorUsername.setLabel(UserUtil.getUserName());
        logger.info("isMenu==true....");
        Executions.createComponents(Pages.MENU_FILE, topHeader.getFellow("menuDiv"), null);
        UserUtil.setSession(true);
    }

    topHeader.invalidate();

    Center center = mainlayout.getCenter();
    center.getChildren().clear();
    logger.info("contentPage: " + contentPage);
    Executions.createComponents(contentPage, center, null);

}

}

please help me on this

Let me update you. 1. first time no refresh 2. after login, when i click on logout and go to login page, as soon as i add the value in any of the textbox, pages refreshes. no action is written on any of those fields.

delete flag offensive retag edit

Comments

worst forum on planet

qasibeat ( 2013-03-25 11:57:24 +0800 )edit

Please have in mind, that most of the people here spend their free time for answers. Without having looked too much into your question, it may help if you simplify the code in a way that somebody can also run it in its own environment.

Matze2 ( 2013-03-25 12:34:12 +0800 )edit

Agree with @Matze2 we are not fool who are wasting out time in forum people getting answer from this official forum as well dont write something without know any truth

sjoshi ( 2013-03-25 17:09:56 +0800 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2013-03-25 17:11:05 +0800

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

I already given answer of this type of question here Stackoverflow may be i missed this question in Official forum

link publish delete flag offensive edit

Comments

@sjoshi i had other questions too, but not a single question was answered. But yes stackoverflow is good and you answered my question there. thanks for that. but i would again say, this forum is not helpful

qasibeat ( 2013-04-18 09:18:26 +0800 )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: 2013-03-19 12:25:04 +0800

Seen: 47 times

Last updated: Mar 25 '13

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