package com.udapsoft.modular.web.tags;

import java.util.Map;

import com.udapsoft.modular.core.util.StringUtils;

public class ItemTag extends TemplateBasedRequestContextAwareTag {

	private static final long serialVersionUID = -2718374272714310640L;
	private String text;
	private String value;

	public String getText() {
		return this.text;
	}

	public void setText(String display) {
		this.text = display;
	}

	public String getValue() {
		return this.value;
	}

	public void setValue(String message) {
		this.value = message;
	}

	protected int doBuildModelForStartTag(Map model) throws Exception {
		evaluateStringAndSetModel(model, "text", this.pageContext);
		evaluateStringAndSetModel(model, "value", this.pageContext);

		model.put("id", this.pageContext.getAttribute("id"));
		model.put("display", this.pageContext.getAttribute("display"));
		model.put("selected", this.pageContext.getAttribute("selected"));
		model.put("separator", this.pageContext.getAttribute("separator"));

		return 1;
	}

	protected int doBuildModelForEndTag(Map model) throws Exception {
		if (StringUtils.hasText(this.text)) {
			return 5;
		}
		model.put("display", this.pageContext.getAttribute("display"));
		return 6;
	}

}
