Skip to main content

Posts

Showing posts with the label Data Tag

Struts Generic Tags

The struts generic tags are used to control the execution flow when pages are rendered. Another use of struts generic tags are data extraction. Further Generic Tags are classified into Control Tags and Data Tags. Control Tags: The Control Tags are used for flow control, such as if, else and iterate. Here are the list of Control Tags: * if tag - Details * elseIf tag - Details * else tag - Details * append tag - Details * generator tag - Details * iterator tag - Details * merge tag - Details * subset tag - Details Data Tags: The Data Tags are used for data manipulation or creation, such as bean, push, and i18n. Here are the list of Data Tags: * action - Details * bean - Details * date - Details * include - Details * param - Details * set - Details * text - Details * property - Details Struts UI tags: Struts UI Tags are mainly designed to use the data from your action/value stack or from Data Tags. These tags are used to display the data on the...

Struts2 - Property Tag (Data Tags)

In this section, we are going to describe the property tag. The property tag is a generic tag that is used to get the property of a value, which will default to the top of the stack if none is specified. Add the following code snippet into the struts.xml file. struts.xml <action name="propertyTag" class="net.struts2.propertyTag">   <result>/pages/genericTags/propertyTag.jsp</result> </action> Create an action class as shown: propertyTag.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; public class propertyTag extends ActionSupport {   public String execute() throws Exception{   return SUCCESS;   } } Create a bean class " companyName " as shown: companyName.java package net.struts2; public class companyName {      private String name;   public voi...

Struts2 - Text Tag (Data Tags)

In this section, we are going to describe the text tag. The text tag is a generic tag that is used to render a I18n text message. Follow one of the three steps: 1. Keep the message to be displayed in a resource bundle with the same name as the action that it is associated with ie. create a properties file in the same package as your Java class with the same name as your class, but with .properties extension. 2. If the property file does-not work or the message is not found in the resource bundle, then the body of the tag will be used as default message. 3. If there is no body, then the name of the message will be used. Add the following code snippet into the struts.xml file. struts.xml <action name="textTag" class="net.struts2.textTag">    <result>/pages/genericTags/textTag.jsp</result> </action> Create an action class as shown below: textTag.java package net.struts2; import com.opensymphony.xwork2.ActionSuppor...

Struts2 - Set Tag (Data Tags)

In this section, we are going to describe the Set tag. The set tag is a generic tag that is used to assign a value to a variable in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. Add the following code snippet into the struts.xml file. struts.xml <action name="setTag">    <result>/pages/genericTags/setTag.jsp</result> </action> Now create a jsp page using tag as shown in the setTag.jsp page. The set tag is used to assign a value to a variable in a specified scope. The parameters name and value in the tag acts as the name-value pair. Here we set the parameters as name="technologyName" value="Java". setTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Set Tag (Data Tag) Example!</title>...

Struts2 - Param Tag (Data Tags)

In this section, we are going to describe the param tag. The param tag is a generic tag that is used to parameterize other tags. For example the include tag and bean tag. The parameters can be added with or without a name as a key. The param tag has the following two parameters. 1. name (String) - the name of the parameter 2. value (Object) - the value of the parameter Note: When you declare the param tag, the value can be defined in either a value attribute or as text between the start and end tag. Struts behaves a bit different according to these two situations. Case 1. AmitHere the value would be evaluated to the stack as a java.lang.String object. Case 2. Here the value would be evaluated to the stack as a java.lang.Object object. Add the following code snippet into the struts.xml file. struts.xml <action name="paramTag">   <result>/pages/genericTags/paramTag.jsp</result> </action> Now create a jsp page to see the w...

Struts2 - Include Tag (Data Tag)

In this section, we are going to describe the include tag. The include tag is a generic tag that is used to include a servlet's output (result of servlet or a JSP page) to the current page. Add the following code snippet into the struts.xml file. struts.xml <action name="includeTag" class="net.roseindia.includeTag">    <result name="success">/pages/genericTags/includeTag.jsp</result> </action> Create an action class as shown below: includeTag.java package net.roseindia; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class includeTag extends ActionSupport {   private Date myBirthday;   public String execute() throws Exception{   setMyBirthday(new Date("Jan 12, 1984 11:21:30 AM"));   return SUCCESS;   }  ...

Struts2 - Date Tag (Data Tag)

In this section, we are going to describe the Date tag. The date tag allows to format a Date in a quick and easy way. User can specify a custom format (eg. "dd/MM/yyyy hh:mm"), can generate easy readable notations (like "in 2 hours, 14 minutes"), or can just fall back on a predefined format with key 'struts.date.format' in the properties file. If that key is not defined, it will finally fall back to the default DateFormat.MEDIUM formatting. Note: If the requested Date object isn't found on the stack, a blank will be returned. Configurable attributes are :- 1. name 2. nice 3. format Add the following code snippet into the "struts.xml" file. struts.xml <action name="dateTag" class="net.roseindia.dateTag">    <result name="success">/pages/genericTags/dateTag.jsp</result> </action> Create an action class as shown below: dateTag.java package net.roseindia; import com.opensympho...

Struts2 - Bean Tag (Data Tag)

In this section, we are going to describe the Bean Tag. The Bean tag is a generic tag that is used to instantiates a class that confirms to the JavaBeans specification. This tag has a body which can contain a number of Param elements to set any mutator methods on that class. If the id attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context. Add the following code snippet into the struts.xml file. struts.xml <action name="beanTag" class="struts2.actionTag"> <result name="success">/pages/genericTags/bean.jsp</result>  </action> Create an action class as shown below: beanTag.java package net.struts2;  import com.opensymphony.xwork2.ActionSupport; public class beanTag extends ActionSupport {    public String execute() throws Exception{     return SUCCESS;   } }...

Struts2 - Action Tag (Data Tag)

In this section, we are going to describe the action tag. The action tag is a generic tag that is used to call actions directly from a JSP page by specifying the action name and an optional namespace. The body content of the tag is used to render the results from the Action. Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified. Add the following code snippet into the struts.xml file. struts.xml <action name="actionTag" class="struts.actionTag"> <result name="success">/pages/genericTags/success.jsp</result>  </action> Create an action class as shown below: actionTag.java package net.roseindia;  import com.opensymphony.xwork2.ActionSupport; public class actionTag extends ActionSupport {     public String execute() throws Exception{    ...