javazkzul

zk framework: how to load zul pages from WEB-INF under directory zul


I am using zk framework 6. I am trying to put my zul pages in /WEB-INF/zul directory. My index.zul file forwards the request to /WEB-INF/zul/login.zul which has a composer LoginComposer. But when I am on login page I want to redirect the user to another page e.g. home.zul. But I am getting 404 error.

Both login.zul and home.zul are in zul directory along with their respective composers.

in loginComposer.java i have the following code to redirect to the home page which is called on a button click.

 Execution exec = Executions.getCurrent();
                HttpServletResponse response = (HttpServletResponse)exec.getNativeResponse();
                response.sendRedirect(response.encodeRedirectURL("/WEB-INF/zul/home.zul")); //assume there is /login
                exec.setVoided(true); 

I created the project as a zk project from eclipse and i made no changes to web.xml.

please guide me how can i go from here.

Thank in advance.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>abc</display-name>
  <listener>
    <description>
    Used to cleanup when a session is destroyed</description>
    <display-name>ZK Session cleaner</display-name>
    <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
  </listener>
  <servlet>
    <description>
    The ZK loader for ZUML pages</description>
    <servlet-name>zkLoader</servlet-name>
    <servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
    <init-param>
        <param-name>update-uri</param-name>
        <param-value>/zkau</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <description>
    The asynchronous update engine for ZK</description>
    <servlet-name>auEngine</servlet-name>
    <servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zul</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zhtml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>auEngine</servlet-name>
    <url-pattern>/zkau/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>index.zul</welcome-file>
  </welcome-file-list>
</web-app>

zk.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Created by ZK Studio
-->

<zk>

        <device-config>
            <device-type>ajax</device-type>
            <timeout-uri>/timeout.zul</timeout-uri><!-- An empty URL can cause the browser to reload the same URL -->
        </device-config>

    </zk>

LoginComposer.java

public class LoginComposer extends SelectorComposer<Component>{

    private static final long serialVersionUID = -1657004425904043268L;

    @Wire
    private Button buttontestButton;

    @Listen("onClick = #testButton")
    public void cancelButton(){


             Executions.sendRedirect("/WEB-INF/zul/home.zul");


    }
}

Solution

  • It is not possible

    I looked around and found a german site tht explains, that the spec
    of java-servlet define the WEB-INF folder as not client accessable,
    cos it contains data as classes that never should be accessed from outside the server.

    If you have the problems in a folder that is not WEB-INF:

    You should better use Executions.sendRedirect(java.lang.String uri)
    to redirect by a button click with server-side action needed.
    If you just want to redirect, set the buttons href.
    It should look like

    Executions.sendRedirect("/zul/home.zul");
    

    or in java:

    myButton.setHref("/zul/home.zul");
    

    in zul:

    <button ... href="/zul/home.zul" ...>
    

    Edit

    I could write much, but the best would be to say, if you

    1. do not use Spring follow this and if you get 404
      check your deploy options/ deployed stuff.
    2. use Spring, what I would prefer because of easy
      ajax login site, security annotations at java methods
      and easy zk integration, follow the zk guide for spring.

    If you still have 404 and can't figure them out, please post your
    configuration files or classes.