Skip to main content

Posts

Showing posts from August, 2011

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{    ...