3

I'm using Zk framework and trying to get a url parameter from zhtml page. I've tried:

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

It doesn't work for zhtml although I tried both zscript in the client side and page composer in the server side. But it is working for a zul page. How can I get a url parameter of zhtml as an example:

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

Here is my zhtml page:

<!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>

And server side:

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;
    }
}
Brucevilla
  • 156
  • 2
  • 13

1 Answers1

1

Your problem is actually that the

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

Is only available in the doAfterCompose cyclus.

Asked it there and save it as a global string.

chillworld
  • 4,207
  • 3
  • 23
  • 50