Skip to main content

Posts

Showing posts from October, 2011

Struts2 - Radio Tag (Form Tags)

In this section, we are going to describe the radio tag. The radio tag is a UI tag that renders a radio button input field. Add the following code snippet into the struts.xml file. struts.xml <action name="radioTag" class="net.struts2.checkboxlistTag">   <result>/pages/uiTags/radioTag.jsp</result> </action> Create an action class with two lists as shown below: checkboxlistTag.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class checkboxlistTag extends ActionSupport{      private List fruits;   private List animals;     public String execute()throws Exception{   fruits = new ArrayList();   fruits.add("Apple");   fruits.add("Mango");   fruits.add("Orange");   fruits.add("Pine Apple");  ...

Struts2 - Optgroup Tag (Form Tags)

In this section, we are going to describe the optgroup tag. The optgroup tag is a UI tag that creates an optgroup component which needs to reside within a select tag <s:select>. Add the following code snippet into the struts.xml file. struts.xml <action name="optgroupTag">    <result>/pages/uiTags/optgroupTag.jsp</result> </action> Create a jsp using the tag <s:optgroup> within the <s:select> tag. It creates an optgroup component. This tag contains few parameters: The label parameter sets the label attribute In our case we have set it to " Hardware " and " Software ". optgroupTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Optgroup Tag Example!</title>    </head>   <body>  <h1><span style="background-color: #FFFFcc">Optgroup Tag Ex...

Struts2 - Optiontransferselect Tag (Form Tags)

In this section, we are going to describe the Optiontransferselect tag. The Optiontransferselect tag is a UI tag that creates an option transfer select component. There are two <select ...> tags with buttons in the middle of them, which allows options in each of the <select ...> to be moved between them. It auto-selects all its elements upon its containing form submission. NOTE: The id and doubleId parameters are not needed to supply as they will get generated when the optiontransferselect tag is being used in a form tag. The generated id and doubleId will be <form_id>_<optiontransferselect_doubleName> and <form_id>_<optiontransferselect_doubleName> respectively. Add the following code snippet into the struts.xml file. struts.xml <action name="optiontransferselectTag">   <result>/pages/uiTags/optiontransferselectTag.jsp</result> </action> Create a jsp using the tag...

Struts2 - Password Tag (Form Tags)

In this section, we are going to describe the password tag. The password tag is a UI tag that renders an HTML input tag of type password. Add the following code snippet into the struts.xml file. struts.xml <action name="passwordTag"> <result>/pages/uiTags/passwordTag.jsp</result> </action> Create a jsp using the tag <s:password> . It renders an HTML input tag of type password. passwordTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Password Tag Example!</title>    </head>   <body>   <h1><span style="background-color: #FFFFcc">Password Tag Example! </span></h1>  <s:form>  <s:password label="Enter Password" name="password" size="10" maxlength="8" />   </s:form>   ...

Struts2 - Label Tag (Form Tags)

In this section, we are going to describe the label tag. The label tag is a UI tag that is used to render an HTML LABEL that allows us to output label:name type of combinations that has the same format treatment as the rest of UI controls. Add the following code snippet into the struts.xml file. struts.xml <action name="labelTag">    <result>/pages/uiTags/labelTag.jsp</result> </action> Create a jsp using the tag <s:label> . It renders an HTML LABEL that allows us to output <s: label name=" " value=" " /> combination that has the same format treatment as the rest of UI controls. labelTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Label Tag Example!</title>   </head>   <body>   <h1><span style="background-color: #FFFFcc">Label Tag Example...

Struts2 - Doubleselect Tag (Form Tags)

In this section, we are going to describe the doubleselect tag. The doubleselect tag is a UI tag that renders two HTML select elements with second one changing displayed values depending on selected entry of first one. Add the following code snippet into the struts.xml file. struts.xml <action name="doubleselectTag">   <result>/pages/uiTags/doubleselectTag.jsp</result> </action> Create a jsp using the tag <s:doubleselect> that renders two HTML select elements with second one changing displayed values depending on selected entry of first one. This tag contains various parameters: The headerKey parameter sets the header key of the second list. Must not be empty. In our case we have set it to"1" The headerValue parameter sets the header value of the second list. In our case we have set it to "--- Please Select ---" The doubleName parameter sets the name for complete component. In our case we have set it as : doub...

Struts2 - File Tag (Form Tags)

In this section, we are going to describe the file tag. The file tag is a UI tag that renders an HTML file input element achieved through browsing. Add the following code snippet into the struts.xml file. struts.xml <action name="fileTag">   <result>/pages/uiTags/fileTag.jsp</result> </action> Create a jsp using the tag . It renders an HTML file input element. The parameter name is used to set a name for element which we have used as name="uploadFile" . and the parameter accept is the HTML accept attribute that indicates the accepted file mime types which we have used as accept ="text/*". fileTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>File Tag Example!</title>   </head>   <body>   <h1><span style="background-color: #FFFFcc">File Tag Example! <...

Struts2 - Form Tag

In this section, we are going to describe the form tag. The form tag is a UI tag that renders HTML an input form. The remote form allows the form to be submitted without the page being refreshed. The results from the form can be inserted into any HTML element on the page. Add the following code snippet into the struts.xml file. struts.xml <action name="formTag"> <result>/pages/uiTags/formTag.jsp</result> </action> Create a jsp using the tag <s:form>.It renders HTML as an input form formTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Form Tag Example!</title>   <link href="<s:url value="/css/main.css"/>"    rel="stylesheet" type="text/css"/>     </head>   <body>   <h1><span style="background-color: #FFFFcc"...