Advertisement
Guest User

dynamic method

a guest
Oct 28th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1.     public static Result create() {
  2.         Class<?> clazz = null;
  3.         try {
  4.             clazz = Class.forName("views.html.user.create");
  5.         } catch (ClassNotFoundException e) {
  6.             // TODO Auto-generated catch block
  7.             e.printStackTrace();
  8.         }
  9.         //assumed you have a String parameter for your template
  10.         java.lang.reflect.Method render = null;
  11.         try {
  12.             render = clazz.getDeclaredMethod("render", String.class);
  13.         } catch (NoSuchMethodException | SecurityException e) {
  14.             // TODO Auto-generated catch block
  15.             e.printStackTrace();
  16.         }
  17.         play.api.templates.Html html = null;
  18.         try {
  19.             html = (play.api.templates.Html) render.invoke(null, form);
  20.         } catch (IllegalAccessException | IllegalArgumentException
  21.                 | InvocationTargetException e) {
  22.             // TODO Auto-generated catch block
  23.             e.printStackTrace();
  24.         }
  25.         return ok(html);
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement