📄 sampledatatag1.java
字号:
package jsp.tags.dapact.samples;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.jsp.JspException;
import jsp.tags.dapact.BaseBodyTagSupport;
import jsp.tags.dapact.lookup.DefaultSelectOption;
import jsp.tags.dapact.tags.data.RetrieveValueByNameInf;
/**
* Title: Data Aware Processing And Control Tags
* Description: Tag library for the processing and controlling the input and output of data.
* Copyright: LGPL (http://www.gnu.org/copyleft/lesser.html)
* Compile Date: @compile_date@
* @author Allen M Servedio
* @amp_sign@version @VERSION@
*/
/**
* Simple data tag used to demonstrate use of data tags with other tags in the system.
* It does not retrieve its data from anywhere useful (it is all hard coded), other
* tags will demonstrate more robust data retrieval. This tag responds to the same
* keys as SampleDataTag2, but returns different values.
*
* <p>Supports the following names:<br />
* <ul>
* <li><b>test1</b> - returns a single string.</li>
* <li><b>test2</b> - returns a single string.</li>
* <li><b>optionlist1</b> - returns an array of DefaultSelectOption.</li>
* <li><b>optionlist2</b> - returns an ArrayList of DefaultSelectOption.</li>
* <li>Default string - if the name is not reconized, it returns a single default string.
* Please note, that you should never really do this (there is a great example in the
* select tag that demonstrates why). You should return null if you do not understand
* what is being asked for so that another tag or data source can respond.</li>
* </ul>
* </p>
*/
public class SampleDataTag1 extends BaseBodyTagSupport implements RetrieveValueByNameInf
{
/**
* Default constructor...
*/
public SampleDataTag1()
{
}
/**
* Called by objects that want to request a value by its name.
*
* @param requestor the object requesting the value or the object that the value
* is being requested for (like with a lookup: you would pass the TagSupport
* object, not the lookup which is what actually calls this function).
* @param name the name of the value to retrieve.
*
* @return the value that was found by the name supplied.
*/
public Object retrieveValueByName(Object requestor, String name)
{
Object result = null;
if (name != null)
{
if (name.equals("test1"))
{
result = "test one found - from data 1";
}
else if (name.equals("test2"))
{
result = "test two found - from data 1";
}
else if (name.equals("optionlist1"))
{
DefaultSelectOption[] list = new DefaultSelectOption[10];
for (int i=0; i < 10; i++)
{
list[i] = (new DefaultSelectOption("val" + i, "Text List 1 - Data 1 - Option " + i));
}
result = list;
}
else if (name.equals("optionlist2"))
{
ArrayList list = new ArrayList();
for (int i=0; i < 10; i++)
{
list.add(new DefaultSelectOption("val" + i, "Text List 2 - Data 1 - Option " + i));
}
result = list;
}
else
{
result = "test default";
}
}
return result;
}
/**
* Called at the end of the tag. Will output the end body tag text and return that
* it wants to have the rest of the page processed.
*
* @exception JspException general JSP exception.
*
* @return EVAL_PAGE so that it continues to process the rest of the page.
*/
public int doEndTag() throws JspException
{
// Write out the result of the body tags.
try
{
try
{
getBodyContent().writeOut(getPreviousOut());
}
catch (NullPointerException e)
{}
}
catch (IOException e)
{
e.printStackTrace();
throw new JspException(e.toString());
}
return super.doEndTag();
}
/*=============================================================================*/
/* PROPERTIES/ATTRIBUTES */
/*=============================================================================*/
/**
* @return Get the name of the object to see if we should use it to look up values.
*/
public String getName()
{
return name;
}
/**
* Set the name of the object to see if we should use it to look up values.
*/
public void setName(String name)
{
this.name = name;
}
private String name;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -