/** * {@link ParameterAware}を探して、コールバックします。 * まず、直接の親タグが{@link ParameterAware}かどうか判定します。 * そうであれば、コールバックして終了します。 * もし、直接の親タグが{@link ParameterAware}ない場合、 * {@link SimpleTagSupport#findAncestorWithClass(JspTag, Class)}を利用して、 * ルートまで{@link ParameterAware}を探して辿ります。 * それでも見つからない場合、処理を終了します。 * @throws JspException {@link JspException} * @throws IOException {@link IOException} */ @Override public void doTag() throws JspException, IOException { super.doTag(); Args.checkNotEmpty(getName()); JspTag s = getParent(); if (!ParameterAware.class.isInstance(s)) { s = SimpleTagSupport.findAncestorWithClass(this, ParameterAware.class); } if (s == null) return; ParameterAware parent = (ParameterAware) s; if (getValues() != null) { parent.awareParameter(name, getValues()); } else { parent.awareParameter(name, getValue()); } }
@Override public void doTag() throws JspException, IOException { JspTag tag = SimpleTagSupport.findAncestorWithClass(this, PaginationTagSupport.class); if(tag != null) { Page page = ((PaginationTagSupport) tag).getCurrent(); if(!page.getLeftGap() && !page.getRightGap()) { // Print out a text marker which will replaced with the appropriate page number // when the pagination data structure is processed this.getJspContext().getOut().print(Pagination.PAGE_MARKER); } } }
public void testEventTagOutsideBuilderTagBase_WithInvalidParent_WithBody() throws Exception { final EventTag tag = new EventTag(); final PrintCharJspFragment body = new PrintCharJspFragment('-'); tag.setJspBody(body); final StringJspWriter out = new StringJspWriter(); tag.setJspContext(new MockJspContext(out)); tag.setParent(new SimpleTagSupport()); tag.setName("someEvent"); try { tag.doTag(); fail(); } catch (JspException ex) { assertEquals("EventTag must be enclosed directly or indirectly by a BuilderTagBase tag.", ex.getMessage()); } assertEquals("", out.getOutput()); }
public void testEventTagOutsideBuilderTagBase_WithInvalidParent_WithEmptyBody() throws Exception { final EventTag tag = new EventTag(); final PrintCharJspFragment body = new PrintCharJspFragment('-'); tag.setJspBody(body); final StringJspWriter out = new StringJspWriter(); tag.setJspContext(new MockJspContext(out)); tag.setParent(new SimpleTagSupport()); tag.setName("someEvent"); try { tag.doTag(); fail(); } catch (JspException ex) { assertEquals("EventTag must be enclosed directly or indirectly by a BuilderTagBase tag.", ex.getMessage()); } assertEquals("", out.getOutput()); }
@Override public void doTag() throws JspException, IOException { JspTag parent = SimpleTagSupport.findAncestorWithClass(this, GroupTagSupport.class); JspWriter out = this.getJspContext().getOut(); if (parent != null) { GroupTagSupport group = (GroupTagSupport) parent; String name = group.getParam(); String type = group.getType(); JspTag component = findAncestorWithClass(this, ComponentMarkerIF.class); // If the combo box is used in the context of a component then // the generated parameter name needs to prefix the name of the component if (component != null) { name = ( (ComponentMarkerIF) component ).getParam() + "." + name; } MutableDTO current = group.getItem(); String valueAttribute = group.getValueAttribute(); this.addAttribute("type", type); this.addAttribute("name", name); this.addAttribute("value", current.getValue(valueAttribute)); this.openTag("input", out); if (this.getJspBody() != null) { this.getJspBody().invoke(null); } this.closeTag("input", out); } }
@Override public void doTag() throws JspException, IOException { JspTag parent = SimpleTagSupport.findAncestorWithClass(this, MessagesTagSupport.class); JspWriter out = this.getJspContext().getOut(); if (parent != null) { MessagesTagSupport messages = (MessagesTagSupport) parent; NotificationDTOIF current = messages.getCurrent(); out.println(current.getMessage()); } }
@Override public void doTag() throws JspException, IOException { JspTag parent = SimpleTagSupport.findAncestorWithClass(this, SelectTagSupport.class); JspWriter out = this.getJspContext().getOut(); if (parent != null) { SelectTagSupport select = (SelectTagSupport) parent; // Get the current item in the select collection ComponentDTO current = select.getCurrent(); // Get the name of the attribute on which the value is determined String valueAttribute = select.getValueAttribute(); // set selected=selected if the current value matches the value stored in // the DTO if (select.getSelectedValues().contains("|" + current.getValue(valueAttribute) + "|")) { this.setSelected("selected"); } // Write the value of the option this.addAttribute("value", current.getValue(valueAttribute)); this.openTag("option", out); if (this.getJspBody() != null) { this.getJspBody().invoke(null); } this.closeTag("option", out); } }
@Override public void doTag() throws JspException, IOException { JspTag parent = SimpleTagSupport.findAncestorWithClass(this, TableTagSupport.class); if (parent != null) { TableTagSupport tag = (TableTagSupport) parent; Table table = (Table) tag.getColumnar(); // Generate a new Pagination data-structure using the supplied query object Pagination pagination = new Pagination(tag.getQuery(), isAsynchronous()); // Loop over all of the pages in the pagination while (pagination.hasNext()) { // Update the current Page to generate current = pagination.next(); if (var != null) { this.getJspContext().setAttribute(var, current); } // Generate the pre HTML, marker, and post HTML for the current page if (this.getJspBody() != null) { this.getJspBody().invoke(current.getWriter()); } } // Add the pagination structure to the table table.setPagination(pagination); } }
@Override public void doTag() throws JspException, IOException { JspTag parent = SimpleTagSupport.findAncestorWithClass(this, LinkTagIF.class); if(parent != null) { ((LinkTagIF) parent).addProperty(name, value); } }
/** * Tests that event tag's parents are scanned deeply to find a BuilderTagBase parent. */ public void testBuildGrid_EventsWithIndirectBuilderParentTag() throws Exception { final EventTag rowStartTag = initEvent("rowStart", '^'); final EventTag rowEndTag = initEvent("rowEnd", '$'); final SimpleTag cellTagParent = new SimpleTagSupport() { @Override public void doTag() throws IOException, JspException { getJspBody().invoke(getJspContext().getOut()); } }; cellTagParent.setJspContext(ctx); cellTagParent.setParent(gridTag); final EventTag cellTag = initEvent(cellTagParent, "cell", '-'); cellTagParent.setJspBody(new CallTagsJspFragment(cellTag)); final CallTagsJspFragment body = new CallTagsJspFragment("foo", rowStartTag, rowEndTag, cellTagParent); gridTag.setJspBody(body); gridTag.rowCount = 3; gridTag.columnCount = 2; gridTag.doTag(); assertTrue(gridTag.buildInvoked); assertTrue(body.invoked); assertEquals("^--$^--$^--$", out.getOutput()); }
@SuppressWarnings("unchecked") protected <T> T findAncestor(Class<? extends BaseTag> clazz) { return (T) SimpleTagSupport.findAncestorWithClass(this, clazz); }