Examples of XTemplate

  • Basic math support


    The following basic math operators may be applied directly on numeric data values:

     + - * / 
    For example:
     public native String getTemplate() /*-{ return ['<p>Name: {name}</p>', '<p>Kids: ', '<tpl for="kids">', '<tpl if="age &gt; 1">',  // <-- Note that the > is encoded '<p>{#}: {name}</p>',  // <-- Auto-number each item '<p>In 5 Years: {age+5}</p>',  // <-- Basic math '<p>Dad: {parent.name}</p>', '</tpl>', '</tpl></p>' ].join(""); ); template.overwrite(someElement, Util.getJsObject(person)); 
  • Execute arbitrary inline code with special built-in template variables


    Anything between {[ ... ]} is considered code to be executed in the scope of the template. There are some special variables available in that code:

    This example demonstrates basic row striping using an inline code block and the xindex variable:

     public native String getTemplate() /*-{ return ['<p>Name: {name}</p>', '<p>Company: {[values.company.toUpperCase() + ", " + values.title]}</p>', '<p>Kids: ', '<tpl for="kids">', '<div class="{[xindex % 2 === 0 ? "even" : "odd"]}">', '{name}', '</div>', '</tpl></p>' ].join(""); ); template.overwrite(someElement, Util.getJsObject(person)); 
  • Template member functions


    One or more member functions can be specified in a configuration object passed into the XTemplate constructor for more complex processing:

     var tpl = new Ext.XTemplate( '<p>Name: {name}</p>', '<p>Kids: ', '<tpl for="kids">', '<tpl if="this.isGirl(name)">', '<p>Girl: {name} - {age}</p>', '</tpl>', // use opposite if statement to simulate 'else' processing: '<tpl if="this.isGirl(name) == false">', '<p>Boy: {name} - {age}</p>', '</tpl>', '<tpl if="this.isBaby(age)">', '<p>{name} is a baby!</p>', '</tpl>', '</tpl></p>', { // XTemplate configuration: compiled: true, disableFormats: true, // member functions: isGirl: function(name){ return name == 'Sara Grace'; }, isBaby: function(age){ return age < 1; } } ); tpl.overwrite(panel.body, data); 
  • com.sencha.gxt.core.client.XTemplates.XTemplate
  • com.tensegrity.wpalo.client.serialization.templates.XTemplate

  • Examples of com.extjs.gxt.ui.client.core.XTemplate

        ToolBar toolBar = new ToolBar();
        toolBar.add(new Button("Apply Template", new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            XTemplate tpl = XTemplate.create(getTemplate());
            xpanel.removeAll();
            xpanel.addText(tpl.applyTemplate(Util.getJsObject(person, 3)));
            xpanel.layout();
          }
        }));
        xpanel.setTopComponent(toolBar);
       
        final ContentPanel cpanel = new ContentPanel();
        cpanel.setHeading("XTemplate Test");
        cpanel.setWidth(500);
        cpanel.setBodyStyleName("pad-text");
       
        final Html html = new Html();
        html.setStyleName("pad-text");

        final TextArea area = new TextArea();
        area.setSize(485, 150);
       
        toolBar = new ToolBar();
        toolBar.add(new Button("Apply Template", new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            String template = area.getValue();
            XTemplate tpl = XTemplate.create(template);
            tpl.overwrite(html.getElement(), Util.getJsObject(person, 3));
          }
        }));
        cpanel.setTopComponent(toolBar);
       
        StringBuilder sb = new StringBuilder();
    View Full Code Here

    Examples of com.extjs.gxt.ui.client.core.XTemplate

              "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.<br/><br/>Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit.");
        }

        List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

        XTemplate tpl = XTemplate.create("<p><b>Company:</b> {name}</p><br><p><b>Summary:</b> {desc}</p>");

        RowExpander expander = new RowExpander();
        expander.setTemplate(tpl);

        configs.add(expander);
    View Full Code Here

    Examples of com.extjs.gxt.ui.client.core.XTemplate

        sb.append("<b>Last:</b> {last}<br>");
        sb.append("<b>Change:</b> {[new Number(values.change).toFixed(2)]}<br>");
        sb.append("<b>Updated:</b> {date:date(\"MM/dd/y\")}<br>");
        sb.append("</div>");

        final XTemplate template = XTemplate.create(sb.toString());
        final HTML html = new HTML();
        html.setWidth("160px");
      
        template.overwrite(html.getElement(), Util.getJsObject(stock));
        hp.add(html);
        // update template when model changes
        stock.addChangeListener(new ChangeListener() {
          public void modelChanged(ChangeEvent event) {
            template.overwrite(html.getElement(), Util.getJsObject(stock));
          }
        });

        FormPanel panel = new FormPanel();
        panel.setHeaderVisible(false);
    View Full Code Here

    Examples of com.sencha.gxt.core.client.XTemplates.XTemplate

        SourceWriter sw = factory.createSourceWriter(context, pw);

        for (JMethod method : toGenerate.getOverridableMethods()) {
          TreeLogger l = logger.branch(Type.DEBUG, "Creating XTemplate method " + method.getName());
          final String template;
          XTemplate marker = method.getAnnotation(XTemplate.class);
          if (marker == null) {
            l.log(Type.ERROR, "Unable to create template for method " + method.getReadableDeclaration()
                + ", this may cause other failures.");
            continue;
          } else {
            if (marker.source().length() != 0) {
              if (marker.value().length() != 0) {
                l.log(Type.WARN, "Found both source file and inline template, using source file");
              }

              InputStream stream = getTemplateResource(context, method.getEnclosingType(), l, marker.source());
              if (stream == null) {
                l.log(Type.ERROR, "No data could be loaded - no data at path " + marker.source());
                throw new UnableToCompleteException();
              }
              template = Util.readStreamAsString(stream);
            } else if (marker.value().length() != 0) {
              template = marker.value();
            } else {
              l.log(Type.ERROR,
                  "XTemplate annotation found with no contents, cannot generate method " + method.getName()
                      + ", this may cause other failures.");
              continue;
    View Full Code Here

    Examples of com.sencha.gxt.core.client.XTemplates.XTemplate

        SourceWriter sw = factory.createSourceWriter(context, pw);

        for (JMethod method : toGenerate.getMethods()) {
          TreeLogger l = logger.branch(Type.DEBUG, "Creating XTemplate method " + method.getName());
          final String template;
          XTemplate marker = method.getAnnotation(XTemplate.class);
          if (marker == null) {
            l.log(Type.ERROR, "Unable to create template for method " + method.getReadableDeclaration()
                + ", this may cause other failures.");
            continue;
          } else {
            if (marker.source().length() != 0) {
              if (marker.value().length() != 0) {
                l.log(Type.WARN, "Found both source file and inline template, using source file");
              }

              InputStream stream = getTemplateResource(context, toGenerate, l, marker.source());
              if (stream == null) {
                l.log(Type.ERROR, "No data could be loaded - no data at path " + marker.source());
                throw new UnableToCompleteException();
              }
              template = Util.readStreamAsString(stream);
            } else if (marker.value().length() != 0) {
              template = marker.value();
            } else {
              l.log(Type.ERROR,
                  "XTemplate annotation found with no contents, cannot generate method " + method.getName()
                      + ", this may cause other failures.");
              continue;
    View Full Code Here

    Examples of com.sencha.gxt.core.client.XTemplates.XTemplate

        private Template createTemplate(Method method) {
          Configuration cfg = new Configuration();
          cfg.setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER);

          XTemplate xTemplate = method.getAnnotation(XTemplate.class);
          if (xTemplate == null) {
            throw new GwtTestException(
                "gwt-test-utils expects to find a @XTemplate annotation on method "
                    + method.toString());
          }

          String templateName = method.toGenericString();

          if (xTemplate.source().length() > 0) {
            InputStream in = method.getDeclaringClass().getResourceAsStream(
                xTemplate.source());

            if (in == null) {
              throw new GwtTestException("Cannot find file @Template source file "
                  + xTemplate.source() + " declared for method " + method);
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            try {
              return new Template(templateName, br, cfg);
            } catch (IOException e) {
              throw new GwtTestException(
                  "Error while trying to get template for method " + method);
            }
          } else {
            return Template.getPlainTextTemplate(templateName, xTemplate.value(),
                cfg);
          }

        }
    View Full Code Here

    Examples of com.tensegrity.wpalo.client.serialization.templates.XTemplate

        add(component);
      }
     
      public void set(XObject input) {
        if (input instanceof XTemplate) {     
          XTemplate template = (XTemplate) input;
          WPaloServiceProvider.getInstance().loadWorksheet(template,
              new Callback<XWorksheet>(){
                public void onSuccess(XWorksheet ws) {
                  XWorkbook wb = ws.getWorkbook();
                  XAccount acc = wb.getAccount();
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.