36 lines
816 B
Java
36 lines
816 B
Java
import javax.servlet.jsp.JspException;
|
|
import javax.servlet.jsp.tagext.SimpleTagSupport;
|
|
import java.io.IOException;
|
|
import java.util.Vector;
|
|
import com.articles.Article;
|
|
|
|
public class ArticlesTag
|
|
extends SimpleTagSupport
|
|
{
|
|
private String var;
|
|
|
|
public void doTag()
|
|
throws JspException, IOException
|
|
{
|
|
Vector<Article> vArts = (Vector<Article>)getJspContext().getAttribute("articles");
|
|
|
|
if (vArts == null)
|
|
{
|
|
getJspContext().setAttribute(this.var, new Article() );
|
|
getJspBody().invoke(null);
|
|
return;
|
|
}
|
|
|
|
for (int i=0; i<vArts.size(); i++)
|
|
{
|
|
getJspContext().setAttribute(this.var, (Article)vArts.get(i) );
|
|
getJspBody().invoke(null);
|
|
}
|
|
}
|
|
|
|
public void setVar( String var )
|
|
{
|
|
this.var = var;
|
|
}
|
|
}
|