我登录/指数ZUL页面加载的两倍,其中,因为我只称这是一次(my login/index zul p

2019-10-17 19:10发布

我使用ZK CE版本6.5和我有一个问题。 我登录/索引页被加载两次。

  1. 当我在注销按钮调用此:

    Executions.createComponents( “登录”,中心,NULL);

上述页面有两个领域,我使用MVVM方法。

现在,它加载罚款,但只要我在文本框中输入用户名或输入文本框中的密码,页面将自动刷新。 我在我的代码检查,我不是要求上述方法在其他地方在此过程中。

请告诉我为什么文本/密码文本框我得到这个行为的loginpage。 一旦它重新加载两次,它获取用户名和带我到主页。 现在我注销和同样的情景。

两次,我得到调用此方法,一次是显而易见的,bacause上登出我打电话,但在进入文本框的任何文本,并从中取出的焦点。 那么这个方法被再次调用。

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

我已经检查了我的代码也是如此,没有任何文本字段的任何事件。

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类

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类绘制页面

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);

    }


}

请帮我在这

让我来更新你的。 1.第一次没有刷新2.登录后,当我点击登出去尽快登录页面,正如我在任何文本框中的添加值,页面刷新。 没有动作写上任意字段。

Answer 1:

我无法理解为什么这样做?

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

当你去为注销

从我的理解,你可以做这件事情是这样的...

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


文章来源: my login/index zul page is loading twice, where as i am only calling it once
标签: java zk