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

…衆ロ難τιáo~ 提交于 2019-12-11 08:41:00

问题


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

  1. 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.


回答1:


I am not able to understand why you are doing ...

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

When you going for logout

From my understanding you can do this thing like this...

//Executions.getCurrent().getDesktop().invalidate();//Condition base if you needed use it otherwise dont use it
Executions.getCurrent().getSession().invalidate();
Executions.sendRedirect("/login.zul");


来源:https://stackoverflow.com/questions/15269086/my-login-index-zul-page-is-loading-twice-where-as-i-am-only-calling-it-once

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!