zk - 如何获取 zk zhtml url 参数?

标签 zk url-parameters

我正在使用 Zk 框架并尝试从 zhtml 页面获取 url 参数。我试过:

Executions.getCurrent().getParameter("param");

尽管我在客户端尝试了 zscript 并在服务器端尝试了页面编辑器,但它不适用于 zhtml。但它适用于 zul 页面。我如何获取 zhtml 的 url 参数作为示例:

http://localhost:8080/pystest/reset_password.zhtml?param=xxx

这是我的 zhtml 页面:

<!DOCTYPE html>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<html lang="en" xmlns:zk="zk" xmlns:z="zul">
<head>
    <meta charset="UTF-8"/>
    <title>Reset Password</title>

    <meta name="description" content="User reset password page" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <!-- basic styles -->

    <link href="css/strap.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/font.css" />

    <!-- fonts -->

    <link rel="stylesheet" href="css/ace-fonts.css" />

    <!--styles -->

    <link rel="stylesheet" href="css/min.css" />
    <link rel="stylesheet" href="css/tlr.css" />
</head>
<body class="pass-layout">
    <z:div sclass="main-container" apply="component.ResetPasswordComposer">
            <div class="main-content">
                <div class="row">
                    <div class="col-sm-10 col-sm-offset-1">
                        <div class="pass-container">
                            <div class="position-relative">
                                <div id="resetpass-box" class="resetpass-box visible widget-box no-border">
                                    <div class="widget-body">
                                        <div class="widget-main">
                                            <h4 class="header green lighter bigger">
                                                <i class="icon-group blue"></i>
                                                Choose your new password.
                                            </h4>

                                            <form>
                                                <fieldset>
                                                    <label class="block clearfix">
                                                        <span class="block input-icon input-icon-right">
                                                            <z:textbox type="password" class="form-control" placeholder="New password" id="password1" />
                                                            <i class="icon-lock"></i>
                                                        </span>
                                                    </label>

                                                    <label class="block clearfix">
                                                        <span class="block input-icon input-icon-right">
                                                            <z:textbox type="password" class="form-control" placeholder="Verify password" id="password2"/>
                                                            <i class="icon-retweet"></i>
                                                        </span>
                                                    </label>

                                                    <div class="space-24"></div>

                                                    <div class="clearfix">
                                                        <button type="reset" class="width-30 pull-left btn btn-sm">
                                                            <i class="icon-refresh"></i>
                                                            Reset
                                                        </button>

                                                        <button id="resetButton" type="button" class="width-65 pull-right btn btn-sm btn-success">
                                                            Submit
                                                            <i class="icon-arrow-right icon-on-right"></i>
                                                        </button>
                                                    </div>
                                                </fieldset>
                                            </form>
                                        </div>

                                        <div class="toolbar center">
                                        </div>
                                    </div><!-- /widget-body -->
                                </div><!-- /resetpass-box -->
                            </div><!-- /position-relative -->
                        </div><!-- /pass-container -->
                    </div><!-- /col-sm-10 col-sm-offset-1 -->
                </div><!-- /row -->
            </div><!-- /main-content -->
        </z:div><!-- /main-container -->

        <!-- below script is not working -->
        <zk:zscript>
            <![CDATA[
                alert(Executions.getCurrent().getParameter("param"));     
            ]]>
        </zk:zscript>
</body>
</html>

和服务器端:

public class ResetPasswordComposer extends GenericForwardComposer<Component> {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    protected Textbox password1;
    protected Textbox password2;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
    }

    public void onClick$resetButton(){
        UserOperator userOperator=new UserOperator();
        try{
            String token=getToken();
            System.out.println(token);
        }catch(Exception e){
            e.printStackTrace();
        }

    }

    private String getToken(){
        Execution exec = Executions.getCurrent();
        String param=exec.getParameter("param");
        return param;
    }
}

最佳答案

你的问题其实是

private String getToken(){
    Execution exec = Executions.getCurrent();
    String param=exec.getParameter("param");
    return param;
}

仅在 doAfterCompose cyclus 中可用。

在那里询问并将其保存为全局字符串。

关于zk - 如何获取 zk zhtml url 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20813446/

相关文章:

javascript - 如何将 URL 参数与 Vanilla JS 中的输入字段绑定(bind)?

java - Liferay 获取 URL 参数问题

c# - 通过 '&' ,从选定的选项值返回,在 url

mask - 如何屏蔽日期框

java - ZK如何一次显示300个列表头

java - ZK 我们可以保存 Windows 组件状态吗?

java - 从 LStbox ZK 中的多项选择中获取值

java - zk中Messagebox.show()如何实现双语?

Ruby 的法拉第 - 多次包含相同的参数

python-3.x - 如何使用 Flask/Python 3 处理 URL 中丢失的参数