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

The following examples show how to use org.springframework.web.servlet.tags.form.TagWriter. These examples are extracted from open source projects. 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
@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 2
Source Project: bbs   Source File: FormErrorsTag.java    License: 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 3
Source Project: dubai   Source File: BSCheckboxesTag.java    License: 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 4
Source Project: dubai   Source File: BSAbstractMultiCheckedElementTag.java    License: 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 5
Source Project: onetwo   Source File: LinkTag.java    License: 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 6
@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 7
Source Project: dubai   Source File: BSAbstractMultiCheckedElementTag.java    License: 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 8
Source Project: dubai   Source File: BSAbstractMultiCheckedElementTag.java    License: 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 9
Source Project: spring-analysis-note   Source File: BindTagTests.java    License: 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 10
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 11
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 12
Source Project: openemm   Source File: SpringFormTag.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 13
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 14
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 15
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 16
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 17
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 18
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 19
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 20
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 21
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 22
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 23
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 24
@Override
protected TagWriter createTagWriter() {
    return new CustomTagWriter(pageContext);
}
 
Example 25
Source Project: java-technology-stack   Source File: BindTagTests.java    License: 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 26
Source Project: spring4-understanding   Source File: BindTagTests.java    License: 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 27
Source Project: onetwo   Source File: BaseBodyTag.java    License: Apache License 2.0 4 votes vote down vote up
protected TagWriter createTagWriter(){
	return new TagWriter(pageContext);
}
 
Example 28
Source Project: onetwo   Source File: BaseBodyTag.java    License: Apache License 2.0 4 votes vote down vote up
protected void writeCustomTagAttributes(TagWriter tagWriter) throws JspException{
}
 
Example 29
Source Project: onetwo   Source File: LinkTag.java    License: 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 30
Source Project: sinavi-jfw   Source File: PageNavigationTag.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected int writeTagContent(TagWriter tagWriter) throws JspException {
    return EVAL_BODY_INCLUDE;
}