Skip to content

Instantly share code, notes, and snippets.

@masukomi
Created March 12, 2009 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masukomi/78303 to your computer and use it in GitHub Desktop.
Save masukomi/78303 to your computer and use it in GitHub Desktop.
public class MyAction extends ActionSupport implements TemplateMethodModel {
/*Your functionality here */
/**
* when you need to display a localized piece of text in
* the ftl just use ${text("some.property.name")}
* there should be a package.properties or ClassName.properties
* file in the same source package directory as the Action that
* will be using them. There *is* a way to set a global properties file
* but I don't know the details.
* Obviously the text for other languages would be specified in files like
* package_en_US.properties
* @return an implementation of TemplateMethodModel which takes a
* one parameter method, the parameter is the name of the localized property
* you want to access.
*/
public TemplateMethodModel getText(){
return this;
}
public TemplateModel exec(List args) throws TemplateModelException {
if (args.size() != 1) {
throw new TemplateModelException("Wrong arguments");
}
return new SimpleScalar(getText((String)args.get(0)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment