Example usage for org.apache.wicket.velocity.markup.html VelocityPanel add

List of usage examples for org.apache.wicket.velocity.markup.html VelocityPanel add

Introduction

In this page you can find the example usage for org.apache.wicket.velocity.markup.html VelocityPanel add.

Prototype

public MarkupContainer add(final Component... children) 

Source Link

Document

Adds the child component(s) to this container.

Usage

From source file:ca.travelagency.BasePrintPage.java

License:Apache License

public BasePrintPage(String velocityTemplate, IModel<?> model) {
    super(model);
    Validate.notBlank(velocityTemplate);

    Map<String, Object> map = getObjectMap();
    map.put("company", getCompany());
    map.put("dateUtils", new VelocityDateUtils());
    map.put("stringUtils", new VelocityStringUtils());
    MapModel<String, Object> context = new MapModel<String, Object>(map);

    URL resource = ContextClassLoaderUtils.getResource(velocityTemplate + EXTENSION);
    IResourceStream templateResource = new UrlResourceStream(resource);

    VelocityPanel velocityPanel = VelocityPanel.forTemplateResource(PREVIEW, context, templateResource);
    velocityPanel.add(new LogoImage(LOGO_IMAGE));
    add(velocityPanel);//from  w  w  w  . ja  v a2  s.  co  m

    add(new Label(TITLE, getPageTitle()));
}

From source file:de.alpharogroup.wicket.components.velocity.VelocityFieldsPanel.java

License:Apache License

/**
 * Instantiates a new {@link VelocityFieldsPanel}.
 *
 * @param id//from www . j  a v  a 2  s .  c o m
 *            the id
 * @param model
 *            the model
 */
public VelocityFieldsPanel(final String id, final IModel<List<WicketField<?>>> model) {
    super(id, model);
    final Map<String, List<WicketField<?>>> map = new HashMap<>();
    map.put("fields", model.getObject());
    final StringBuilder sb = new StringBuilder();

    for (final SimpleTag tag : model.getObject()) {
        sb.append(tag.toString());
    }
    final String tmp = sb.toString();

    final IResourceStream template = new StringResourceStream(tmp);
    final VelocityPanel velocityPanel = new VelocityPanel("velocityPanel", new MapModel<>(map)) {

        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        /**
         * {@inheritDoc}
         */
        @Override
        protected IResourceStream getTemplateResource() {
            return template;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected boolean parseGeneratedMarkup() {
            return true;
        }
    };
    add(velocityPanel);
    for (final WicketField<?> field : model.getObject()) {
        addChildComponent(field);
        velocityPanel.add(field.getComponent());
    }
}