~leon/play/1.1

« back to all changes in this revision

Viewing changes to framework/src/play/mvc/Controller.java

  • Committer: Leon Radley
  • Date: 2010-03-17 08:29:29 UTC
  • Revision ID: leon@leon.local-20100317082929-a13s7dv10iv8u73q
added controller method renderTemplate(Template template)

Show diffs side-by-side

added added

removed removed

Lines of Context:
499
499
        }
500
500
    }
501
501
 
 
502
        /**
 
503
     * Render a specific template
 
504
     * @param template The template
 
505
     * @param args The template data
 
506
     */
 
507
    protected static void renderTemplate(Template template, Object... args) {
 
508
        // Template datas
 
509
        Scope.RenderArgs templateBinding = Scope.RenderArgs.current();
 
510
        for (Object o : args) {
 
511
            List<String> names = LocalVariablesNamesTracer.getAllLocalVariableNames(o);
 
512
            for (String name : names) {
 
513
                templateBinding.put(name, o);
 
514
            }
 
515
        }
 
516
        templateBinding.put("session", Scope.Session.current());
 
517
        templateBinding.put("request", Http.Request.current());
 
518
        templateBinding.put("flash", Scope.Flash.current());
 
519
        templateBinding.put("params", Scope.Params.current());
 
520
        try {
 
521
            templateBinding.put("errors", Validation.errors());
 
522
        } catch (Exception ex) {
 
523
            throw new UnexpectedException(ex);
 
524
        }
 
525
        try {
 
526
                        if(template == null)
 
527
                                throw new TemplateNotFoundException("");
 
528
                        
 
529
            throw new RenderTemplate(template, templateBinding.data);
 
530
        } catch (TemplateNotFoundException ex) {
 
531
            if(ex.isSourceAvailable()) {
 
532
                throw ex;
 
533
            }
 
534
            StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex);
 
535
            if (element != null) {
 
536
                throw new TemplateNotFoundException(template.name, Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber());
 
537
            } else {
 
538
                throw ex;
 
539
            }
 
540
        }
 
541
    }
 
542
 
502
543
    /**
503
544
     * Render the corresponding template
504
545
     * @param args The template data