org.springframework.web.servlet.tags.form.TagWriter Java Examples

The following examples show how to use org.springframework.web.servlet.tags.form.TagWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BSAbstractMultiCheckedElementTag.java    From dubai with MIT License 6 votes vote down vote up
/**
 * Copy & Paste, 无修正.
 */
private void writeObjectEntry(TagWriter tagWriter, String valueProperty, String labelProperty, Object item,
		int itemIndex) throws JspException {

	BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
	Object renderValue;
	if (valueProperty != null) {
		renderValue = wrapper.getPropertyValue(valueProperty);
	} else if (item instanceof Enum) {
		renderValue = ((Enum<?>) item).name();
	} else {
		renderValue = item;
	}
	Object renderLabel = (labelProperty != null ? wrapper.getPropertyValue(labelProperty) : item);
	writeElementTag(tagWriter, item, renderValue, renderLabel, itemIndex);
}
 
Example #2
Source File: BSCheckboxesTag.java    From dubai with MIT License 6 votes vote down vote up
@Override
protected int writeTagContent(TagWriter tagWriter) throws JspException {
	super.writeTagContent(tagWriter);

	if (!isDisabled()) {
		// Write out the 'field was present' marker.
		tagWriter.startTag("input");
		tagWriter.writeAttribute("type", "hidden");
		String name = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName();
		tagWriter.writeAttribute("name", name);
		tagWriter.writeAttribute("value", processFieldValue(name, "on", getInputType()));
		tagWriter.endTag();
	}

	return SKIP_BODY;
}
 
Example #3
Source File: FormErrorsTag.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void renderDefaultContent(TagWriter tagWriter) throws JspException {
	tagWriter.startTag(getElement());
	writeDefaultAttributes(tagWriter);
//	String delimiter = ObjectUtils.getDisplayString(evaluate("delimiter", getDelimiter()));
	String[] errorMessages = getBindStatus().getErrorMessages();	
	for (int i = errorMessages.length-1; i < errorMessages.length; i++) {
		String errorMessage = errorMessages[i];
	//	if (i > 0) {
		//	tagWriter.appendValue(delimiter);//换行
	//	}
		
		tagWriter.appendValue(getDisplayString(errorMessage));
	}
	tagWriter.endTag();
}
 
Example #4
Source File: FormFirstErrorsTag.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void renderDefaultContent(TagWriter tagWriter) throws JspException {
	tagWriter.startTag(getElement());
	writeDefaultAttributes(tagWriter);
//	String delimiter = ObjectUtils.getDisplayString(evaluate("delimiter", getDelimiter()));
	String[] errorMessages = getBindStatus().getErrorMessages();	
	for (int i = 0; i < errorMessages.length; i++) {
//	for (int i = errorMessages.length-1; i < errorMessages.length; i++) {
		String errorMessage = errorMessages[i];
	//	if (i > 0) {
		//	tagWriter.appendValue(delimiter);//换行
	//	}

		tagWriter.appendValue(getDisplayString(errorMessage));
		break;
	}
	tagWriter.endTag();
}
 
Example #5
Source File: BSAbstractMultiCheckedElementTag.java    From dubai with MIT License 5 votes vote down vote up
/**
 * 重载方法,调整元素的输出顺序。
 */
private void writeElementTag(TagWriter tagWriter, Object item, Object value, Object label, int itemIndex)
		throws JspException {
	String id = resolveId();

	String resolvedLabelClass = getInputType();
	if (labelCssClass != null) {
		resolvedLabelClass += " " + labelCssClass;
	}

	tagWriter.startTag("label");
	tagWriter.writeAttribute("for", id);

	tagWriter.writeAttribute("class", resolvedLabelClass);

	if (itemIndex > 0) {
		Object resolvedDelimiter = evaluate("delimiter", getDelimiter());
		if (resolvedDelimiter != null) {
			tagWriter.appendValue(resolvedDelimiter.toString());
		}
	}
	tagWriter.startTag("input");

	writeOptionalAttribute(tagWriter, "id", id);
	writeOptionalAttribute(tagWriter, "name", getName());
	writeOptionalAttributes(tagWriter);
	tagWriter.writeAttribute("type", getInputType());
	renderFromValue(item, value, tagWriter);
	tagWriter.endTag();

	tagWriter.appendValue(convertToDisplayString(label));
	tagWriter.endTag();
}
 
Example #6
Source File: BSAbstractMultiCheckedElementTag.java    From dubai with MIT License 5 votes vote down vote up
/**
 * Copy & Paste, 无修正.
 */
private void writeMapEntry(TagWriter tagWriter, String valueProperty, String labelProperty, Map.Entry entry,
		int itemIndex) throws JspException {

	Object mapKey = entry.getKey();
	Object mapValue = entry.getValue();
	BeanWrapper mapKeyWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapKey);
	BeanWrapper mapValueWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapValue);
	Object renderValue = (valueProperty != null ? mapKeyWrapper.getPropertyValue(valueProperty) : mapKey.toString());
	Object renderLabel = (labelProperty != null ? mapValueWrapper.getPropertyValue(labelProperty) : mapValue
			.toString());
	writeElementTag(tagWriter, mapKey, renderValue, renderLabel, itemIndex);
}
 
Example #7
Source File: SessionConversationIdTag.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected int writeTagContent(TagWriter tagWriter) throws JspException {
    
    // first try to pull value from request attribute.
    String conversationId = (String)pageContext.getRequest().getAttribute(attributeName + "_cId");
    
    // if no value was found then try to pull value as request parameter.
    if (conversationId == null || conversationId.trim().length() == 0) {
        conversationId = pageContext.getRequest().getParameter(attributeName + "_cId");
    }
    
    // if a conversation Id was found then process it.
    if (conversationId != null && conversationId.trim().length() > 0) {
        
        // set the request attribute.
        pageContext.getRequest().setAttribute("curr_" + attributeName + "_cId", conversationId);
        
        if (createHiddenInput) {
            // now create the hidden input field.
            tagWriter.startTag("input");
            tagWriter.writeAttribute("type", "hidden");
            tagWriter.writeAttribute("name", attributeName + "_cId");
            tagWriter.writeAttribute("value", conversationId);
            tagWriter.endTag();
        }
    }
    
    return EVAL_PAGE;
}
 
Example #8
Source File: LinkTag.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public void writeCustomTagAttributes(TagWriter tagWriter) throws JspException {
	String linkAddress = href;
	
	if(keepQueryString){
		String qs = WebHolder.getSpringContextHolderRequest().get().getQueryString();
		if(StringUtils.isBlank(qs)){
			writeHref(tagWriter, linkAddress);
			return ;
		}
		linkAddress += linkAddress.contains("?")?"&":"?";
		linkAddress += qs;
	}
	writeHref(tagWriter, linkAddress);
}
 
Example #9
Source File: SpringCheckboxTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #10
Source File: PageNavigationTag.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected int writeTagContent(TagWriter tagWriter) throws JspException {
    return EVAL_BODY_INCLUDE;
}
 
Example #11
Source File: LinkTag.java    From onetwo with Apache License 2.0 4 votes vote down vote up
private void writeHref(TagWriter tagWriter, String linkAddress) throws JspException{
	if(encodeUrl){
		linkAddress = URLEncoder.SAFE_PARAMS_ENCODER.encode(linkAddress);
	}
	tagWriter.writeAttribute("href", linkAddress);
}
 
Example #12
Source File: BaseBodyTag.java    From onetwo with Apache License 2.0 4 votes vote down vote up
protected void writeCustomTagAttributes(TagWriter tagWriter) throws JspException{
}
 
Example #13
Source File: BaseBodyTag.java    From onetwo with Apache License 2.0 4 votes vote down vote up
protected TagWriter createTagWriter(){
	return new TagWriter(pageContext);
}
 
Example #14
Source File: BindTagTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * SPR-4022
 */
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	FormTag formTag = new FormTag() {
		@Override
		protected TagWriter createTagWriter() {
			return new TagWriter(new StringWriter());
		}
	};

	String action = "/form.html";
	String commandName = "tb";
	String name = "formName";
	String enctype = "my/enctype";
	String method = "POST";
	String onsubmit = "onsubmit";
	String onreset = "onreset";
	String cssClass = "myClass";
	String cssStyle = "myStyle";
	String acceptCharset = "iso-8859-1";

	formTag.setName(name);
	formTag.setCssClass(cssClass);
	formTag.setCssStyle(cssStyle);
	formTag.setAction(action);
	formTag.setCommandName(commandName);
	formTag.setEnctype(enctype);
	formTag.setMethod(method);
	formTag.setOnsubmit(onsubmit);
	formTag.setOnreset(onreset);
	formTag.setAcceptCharset(acceptCharset);

	formTag.setPageContext(pc);
	formTag.doStartTag();

	BindTag bindTag1 = new BindTag();
	bindTag1.setPageContext(pc);
	bindTag1.setPath("date");
	bindTag1.doStartTag();
	bindTag1.doEndTag();

	BindTag bindTag2 = new BindTag();
	bindTag2.setPageContext(pc);
	bindTag2.setPath("tb.date");
	bindTag2.doStartTag();
	bindTag2.doEndTag();

	BindTag bindTag3 = new BindTag();
	bindTag3.setPageContext(pc);
	bindTag3.setPath("tb");
	bindTag3.doStartTag();
	bindTag3.doEndTag();

	formTag.doEndTag();
}
 
Example #15
Source File: BindTagTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * SPR-4022
 */
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	FormTag formTag = new FormTag() {
		@Override
		protected TagWriter createTagWriter() {
			return new TagWriter(new StringWriter());
		}
	};

	String action = "/form.html";
	String commandName = "tb";
	String name = "formName";
	String enctype = "my/enctype";
	String method = "POST";
	String onsubmit = "onsubmit";
	String onreset = "onreset";
	String cssClass = "myClass";
	String cssStyle = "myStyle";
	String acceptCharset = "iso-8859-1";

	formTag.setName(name);
	formTag.setCssClass(cssClass);
	formTag.setCssStyle(cssStyle);
	formTag.setAction(action);
	formTag.setModelAttribute(commandName);
	formTag.setEnctype(enctype);
	formTag.setMethod(method);
	formTag.setOnsubmit(onsubmit);
	formTag.setOnreset(onreset);
	formTag.setAcceptCharset(acceptCharset);

	formTag.setPageContext(pc);
	formTag.doStartTag();

	BindTag bindTag1 = new BindTag();
	bindTag1.setPageContext(pc);
	bindTag1.setPath("date");
	bindTag1.doStartTag();
	bindTag1.doEndTag();

	BindTag bindTag2 = new BindTag();
	bindTag2.setPageContext(pc);
	bindTag2.setPath("tb.date");
	bindTag2.doStartTag();
	bindTag2.doEndTag();

	BindTag bindTag3 = new BindTag();
	bindTag3.setPageContext(pc);
	bindTag3.setPath("tb");
	bindTag3.doStartTag();
	bindTag3.doEndTag();

	formTag.doEndTag();
}
 
Example #16
Source File: BindTagTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * SPR-4022
 */
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	FormTag formTag = new FormTag() {
		@Override
		protected TagWriter createTagWriter() {
			return new TagWriter(new StringWriter());
		}
	};

	String action = "/form.html";
	String commandName = "tb";
	String name = "formName";
	String enctype = "my/enctype";
	String method = "POST";
	String onsubmit = "onsubmit";
	String onreset = "onreset";
	String cssClass = "myClass";
	String cssStyle = "myStyle";
	String acceptCharset = "iso-8859-1";

	formTag.setName(name);
	formTag.setCssClass(cssClass);
	formTag.setCssStyle(cssStyle);
	formTag.setAction(action);
	formTag.setModelAttribute(commandName);
	formTag.setEnctype(enctype);
	formTag.setMethod(method);
	formTag.setOnsubmit(onsubmit);
	formTag.setOnreset(onreset);
	formTag.setAcceptCharset(acceptCharset);

	formTag.setPageContext(pc);
	formTag.doStartTag();

	BindTag bindTag1 = new BindTag();
	bindTag1.setPageContext(pc);
	bindTag1.setPath("date");
	bindTag1.doStartTag();
	bindTag1.doEndTag();

	BindTag bindTag2 = new BindTag();
	bindTag2.setPageContext(pc);
	bindTag2.setPath("tb.date");
	bindTag2.doStartTag();
	bindTag2.doEndTag();

	BindTag bindTag3 = new BindTag();
	bindTag3.setPageContext(pc);
	bindTag3.setPath("tb");
	bindTag3.doStartTag();
	bindTag3.doEndTag();

	formTag.doEndTag();
}
 
Example #17
Source File: SpringInputTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #18
Source File: SpringLabelTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #19
Source File: SpringOptionTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #20
Source File: SpringHiddenInputTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #21
Source File: SpringSelectTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #22
Source File: SpringErrorsTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #23
Source File: SpringRadioButtonTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #24
Source File: SpringTextareaTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #25
Source File: SpringButtonTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #26
Source File: SpringCheckboxesTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #27
Source File: SpringPasswordInputTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #28
Source File: SpringFormTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #29
Source File: SpringRadioButtonsTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example #30
Source File: SpringOptionsTag.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}