Example usage for javax.servlet.jsp JspContext setAttribute

List of usage examples for javax.servlet.jsp JspContext setAttribute

Introduction

In this page you can find the example usage for javax.servlet.jsp JspContext setAttribute.

Prototype


abstract public void setAttribute(String name, Object value);

Source Link

Document

Register the name and value specified with page scope semantics.

Usage

From source file:test.pl.chilldev.web.tags.page.LinkTagTest.java

@Test
public void doTag() throws JspTagException {
    JspContext context = new MockPageContext();
    LinkTag tag = new LinkTag();
    tag.setJspContext(context);/*from ww w  .j a v  a2  s . c om*/

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this.page);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    String href = "bar";
    String type = "baz";
    String media = "quux";

    Set<String> rels = new HashSet<>();
    rels.add("qux");

    // run the tag
    tag.setHref(href);
    tag.setRels(rels);
    tag.setType(type);
    tag.setMedia(media);
    tag.doTag();

    verify(this.page).addLink(href, rels, type, media);
}

From source file:test.pl.chilldev.web.tags.page.XmlnsTagTest.java

@Test(expected = JspTagException.class)
public void doTagInvalidModelType() throws URISyntaxException, JspTagException {
    JspContext context = new MockPageContext();
    XmlnsTag tag = new XmlnsTag();
    tag.setJspContext(context);/*from  w w w.  ja v a 2 s . c  om*/

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    // run the tag
    tag.doTag();
}

From source file:test.pl.chilldev.web.tags.page.ScriptTagTest.java

@Test
public void doTag() throws JspTagException {
    JspContext context = new MockPageContext();
    ScriptTag tag = new ScriptTag();
    tag.setJspContext(context);/*w w w.  j av  a 2  s . co  m*/

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this.page);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    String src = "bar";
    String type = "baz";
    Element.Flow flow = Element.Flow.DEFER;
    Charset charset = StandardCharsets.UTF_8;

    // run the tag
    tag.setSrc(src);
    tag.setType(type);
    tag.setFlow(flow);
    tag.setCharset(charset);
    tag.doTag();

    verify(this.page).addScript(src, type, flow, charset);
}

From source file:test.pl.chilldev.web.tags.page.StylesheetTagTest.java

@Test
public void doTag() throws JspTagException {
    JspContext context = new MockPageContext();
    StylesheetTag tag = new StylesheetTag();
    tag.setJspContext(context);/*from   www  .ja  v  a2 s.  c  o m*/

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this.page);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    String href = "bar";
    String type = "baz";
    String media = "quux";

    // run the tag
    tag.setHref(href);
    tag.setType(type);
    tag.setMedia(media);
    tag.doTag();

    verify(this.page).addStylesheet(href, type, media);
}

From source file:test.pl.chilldev.web.tags.page.TitleSeparatorTagTest.java

@Test
public void doTag() throws JspTagException {
    JspContext context = new MockPageContext();
    TitleSeparatorTag tag = new TitleSeparatorTag();
    tag.setJspContext(context);// w w w.  ja  va 2 s . c om

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this.page);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    String separator = " :: ";

    // run the tag
    tag.setSeparator(separator);
    tag.doTag();

    verify(this.page).setTitleSeparator(separator);
}

From source file:test.pl.chilldev.web.tags.page.MetaKeywordsTagTest.java

@Test
public void doTag() throws JspTagException {
    JspContext context = new MockPageContext();
    MetaKeywordsTag tag = new MetaKeywordsTag();
    tag.setJspContext(context);//from ww  w. j  a  va  2s  . c  o  m

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this.page);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    List<String> phrases = new ArrayList<>();
    phrases.add("bar");
    phrases.add("baz");

    // run the tag
    tag.setPhrases(phrases);
    tag.doTag();

    verify(this.page).addKeywords(phrases);
}

From source file:test.pl.chilldev.web.tags.page.XmlnsTagTest.java

@Test
public void doTag() throws URISyntaxException, JspTagException {
    JspContext context = new MockPageContext();
    XmlnsTag tag = new XmlnsTag();
    tag.setJspContext(context);/*from  ww w  . ja  v  a  2s  . c o m*/

    // set up context
    String attribute = "foo";
    context.setAttribute(attribute, this.page);

    // set up resolver
    PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute));

    URI namespace = new URI("http://chilldev.pl/");
    String alias = "cdv";

    // run the tag
    tag.setNamespace(namespace);
    tag.setAlias(alias);
    tag.doTag();

    verify(this.page).setXmlNamespace(namespace, alias);
}

From source file:test.pl.chilldev.web.tags.context.JspPageMetaModelResolverTest.java

@Test
public void getPageMetaModelWithKey() throws PageMetaModelContextException {
    JspContext context = new MockPageContext();
    String attribute = "foo";
    PageMetaModelResolver resolver = new JspPageMetaModelResolver(attribute);

    PageMetaModel page = new PageMetaModel();
    context.setAttribute(attribute, page);
    assertSame(/* ww w  .  j a v a 2s. c o m*/
            "JspPageMetaModelResolver.getPageMetaModel() should return existing page model if it's already in context.",
            page, resolver.getPageMetaModel(context));
}

From source file:test.pl.chilldev.web.tags.context.JspPageMetaModelResolverTest.java

@Test(expected = PageMetaModelContextException.class)
public void getPageMetaModelInvalidType() throws PageMetaModelContextException {
    JspContext context = new MockPageContext();
    String attribute = "foo";
    Generator generator = new Generator(false);
    PageMetaModelResolver resolver = new JspPageMetaModelResolver(attribute, generator);

    context.setAttribute(attribute, resolver);
    resolver.getPageMetaModel(context);/*from   ww w  .  j a  va2  s . c o  m*/
}

From source file:org.lightadmin.core.view.tags.form.DomainTypeElementsTag.java

@Override
public void doTag() throws JspException, IOException {

    DomainTypeBasicConfiguration domainTypeConfiguration = configuration.forDomainType(domainType);
    Assert.notNull(domainTypeConfiguration, "<domainTypeConfiguration> not found for association");

    // TODO: Implement configurable ordering
    List allElements = domainTypeConfiguration.getRepository().findAll();
    allElements = sortByNaturalOrder(allElements, domainTypeConfiguration);

    PersistentProperty idAttribute = domainTypeConfiguration.getPersistentEntity().getIdProperty();
    EntityNameExtractor<Object> nameExtractor = domainTypeConfiguration.getEntityConfiguration()
            .getNameExtractor();/*w w  w  .  ja v  a 2 s  .c  o m*/
    JspContext jspContext = getJspContext();
    JspFragment tagBody = getJspBody();
    for (Object element : allElements) {
        BeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(element);

        jspContext.setAttribute(idVar, beanWrapper.getPropertyValue(idAttribute.getName()));
        jspContext.setAttribute(stringRepresentationVar,
                exceptionAwareNameExtractor(nameExtractor, domainTypeConfiguration).apply(element));
        tagBody.invoke(null);
    }
}