updated for 2.4.0

Url Parameter tutorial#

This tutorial shows how to use url-parameters. In ztemplates-web url parameters are the http parameters. They are assigned before calling the after() callback.

The View#

  • Create a file called UrlParameters.jsp in tutorial/WEB-INF/classes/org/ztemplates/tutorial/urlparameters with the following content. Note that the notation must be EL ${}. This has been enabled in the web.xml of the application in the <jsp-config> setting.
<html>
<h1>${text}</h1>
</html>

The View Model#

  • Create a file called UrlParameters.java in tutorial/WEB-INF/classes/org/ztemplates/tutorial/urlparameters with the following content.
As you can see this class is a passive data-holder.

package org.ztemplates.tutorial.urlparameters;

import org.ztemplates.render.ZExpose;
import org.ztemplates.render.ZRenderer;
import org.ztemplates.web.jsp.ZJspRenderer;


//this tells ztemplates to use JSP as a renderer
//by default the JSP template has the same name as
//the class but with extension '.jsp'

@ZRenderer(ZJspRenderer.class)
public class UrlParameters
{
  //make a property called 'text' available to the renderer
  @ZExpose
  final String text;    
  
  public UrlParameters(String text) 
  {
    this.text= text;
  }
}

The Controller#

  • Create a file UrlParametersAction.java in tutorial/WEB-INF/classes/org/ztemplates/tutorial/urlparameters with the following content. Note the @ZMatch annotation, that specifies the parameters.

package org.ztemplates.tutorial.urlparameters;

import org.ztemplates.actions.ZMatch;
import org.ztemplates.web.ZTemplates;

@ZMatch(value="/urlparameters", parameters={"text"})
public class UrlParametersAction
{
  //same name as parameter
  private String text;


  public void after() throws Exception
  {
    UrlParameters pojo = new UrlParameters(text);
    ZTemplates.getServletService().render(pojo);
  }
}

In the controller we could also have defined the following callbacks:

  • public void before() throws Exception

Build#

  • open a command window and change to the tutorial/WEB-INF/classes directory
  • compile
javac -cp ../lib/ztemplates.jar org/ztemplates/tutorial/urlparameters/*.java

Neuen Anhang hinzuf�gen

Du bist nicht autorisiert, Anh�nge zu dieser Seite hochzuladen.
« Diese Seite (Version-) wurde zuletzt am 22-Dez-2013 13:18 von gerdziegler.de ge�ndert.