1

我正在使用 zk ce 6.5 版,但我遇到了问题。我的登录/索引页面被加载了两次。

  1. 当我在注销按钮上调用这个:

    Executions.createComponents("登录", center, null);

上面的页面有两个字段,我正在使用 MVVM 方法。

现在它加载正常,但是只要我在文本框中输入用户名或在文本框中输入密码,页面就会自动刷新。我已经检查了我的代码,我没有在此处的进程中的其他任何地方调用上述方法。

请告诉我为什么在文本框/密码文本框上我会在登录页面出现这种行为。重新加载两次后,它会获取用户名并将我带到主页。现在我注销和相同的情况。

有两次,我接到了这个方法的调用,一次很明显,因为注销时我调用了它,但是在文本框中输入任何文本并从中删除焦点。然后再次调用此方法。

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

我也检查了我的代码,任何文本字段都没有事件。

登录.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>

登录视图模式类

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.登录后,当我点击注销并进入登录页面时,只要我在任何文本框中添加值,页面就会刷新。没有对这些字段中的任何一个进行任何操作。

4

1 回答 1

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");
于 2013-03-22T12:10:42.423 回答