Struts2 framework provides a tag library from the view technology. In this tutorial ,
we discuss few tag that are mostly we use. Most tags are supported in all template languages (jsp , velocity , freemarker)
but some are currently only specific to one language.
The types of Struts2tags can be broken in to two types: generic and UI. According to function and responsibility.
Generic Tags :- Generic tags are used for controlling the execution flow when the pages render.
Such as Control Tags provide control flow, such as if, else, and iterator. Data Tags allow for data manipulation
or creation, such as bean, push, and i18n.
UI Tags :-Unlike Generic Tags, UI tags do not provide much control structure or logic. Rather,
they are focussed on using data, either from your action/value stack or from the Data Tags, and
displaying data in rich and reusable HTML. All UI tags are driven by templates and themes. While
generic tags simply output some content directly from the tag (if there is any content to output),
the UI tags defer to a template, often grouped together as a theme, to do the actual rendering.
Here is Example to show few UI tag Working :-
web.xml
struts.xml
Bean
Action Class
index.jsp
result.jsp
while executing pproject UI tag are shown like this :-
:)
we discuss few tag that are mostly we use. Most tags are supported in all template languages (jsp , velocity , freemarker)
but some are currently only specific to one language.
The types of Struts2tags can be broken in to two types: generic and UI. According to function and responsibility.
Generic Tags :- Generic tags are used for controlling the execution flow when the pages render.
Such as Control Tags provide control flow, such as if, else, and iterator. Data Tags allow for data manipulation
or creation, such as bean, push, and i18n.
UI Tags :-Unlike Generic Tags, UI tags do not provide much control structure or logic. Rather,
they are focussed on using data, either from your action/value stack or from the Data Tags, and
displaying data in rich and reusable HTML. All UI tags are driven by templates and themes. While
generic tags simply output some content directly from the tag (if there is any content to output),
the UI tags defer to a template, often grouped together as a theme, to do the actual rendering.
Here is Example to show few UI tag Working :-
web.xml
TestStrs struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* index.jsp
struts.xml
/result.jsp
Bean
package com.javastoreroom; public class StudentBean { private int id; private String name; public StudentBean(int id, String name) { this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
Action Class
package com.javastoreroom; import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport; @SuppressWarnings("serial") public class RetrieveAction extends ActionSupport { /** * @author Arun */ private ListnameList = null; public String fetchName() { nameList = new ArrayList (); { nameList.add(new StudentBean(1, "Arun")); nameList.add(new StudentBean(2, "Anu")); nameList.add(new StudentBean(3, "Aryan")); nameList.add(new StudentBean(4, "Anu")); nameList.add(new StudentBean(5, "Aranv")); nameList.add(new StudentBean(6, "Arun")); } return SUCCESS; } public String execute() { return SUCCESS; } public List getNameList() { return nameList; } public void setNameList(List nameList) { this.nameList = nameList; } }
index.jsp
<%response.sendRedirect("fetchName.action");%>
result.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib prefix="s" uri="/struts-tags"%>
while executing pproject UI tag are shown like this :-
:)
No comments:
Post a Comment