Skip to main content

Posts

Showing posts with the label Form 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 - Textfield Tag (Form Tags)

In this section, we are going to describe the textfield tag. The textfield tag is a UI tag that is used to render an HTML input field of type text. Add the following code snippet into the struts.xml file. struts.xml <action name="submitTag">   <result>/pages/uiTags/submitTag.jsp</result> </action> Create a jsp using the tag <s:textfield >  that renders an HTML input field of type text. <s:textfield label="Employee Name" name="empname" size="15" maxlength="10" /> tag displays an HTML text field with label equal to Employee Name with length of 15 columns. textfieldTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>   <title>Textfield Tag Example</title>   </head>   <body>   <h1><span style="background-color: #FFFFcc">Tex...

Struts2 - Submit Tag (Form Tags)

In this section, we are going to describe the submit tag . The submit tag is a UI tag that is used to render a submit button. The submit tag is used with the form tag to provide asynchronous form submissions. The submit can have three different types of rendering: • input: renders as html <input type="submit"...> • image: renders as html <input type="image"...> • button: renders as html <button type="submit"...> Add the following code snippet into the struts.xml file. struts.xml <action name="submitTag">   <result>/pages/uiTags/submitTag.jsp</result> </action> Create a jsp using the tag <s:submit> that renders a submit button. This tag contains various parameters: The value parameter presets the value of input element. In our 1st case we have set it to " Submit " The type parameter sets the type of submit to use. Valid values are input, button and image. In o...

Struts2 - Select Tag (Form Tags)

In this section, we are going to describe the select tag. The select tag is a UI tag that is used to render an HTML input tag of type select. Add the following code snippet into the struts.xml file. struts.xml <action name="selectTag" class="net.struts2.weekDay">    <result>/pages/uiTags/selectTag.jsp</result> </action> Create an action class with a list populated with various items as shown below: weekDay.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class weekDay extends ActionSupport{      private List day;   public String execute()throws Exception{   day = new ArrayList();   day.add("Sunday");   day.add("Monday");   day.add("Tuesday");   day.add("Wednesday");   day.add("Thursday");   day.add("Friday")...

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

Datetimepicker Tag Example

In this section, we are going to describe the datetimepicker tag. The datetimepicker tag is a UI tag that is used to render a date/time picker in a dropdown container. A stand-alone DateTimePicker widget that makes it easy to select a date/time or increment by week, month, and/or year. It is possible to customize the user-visible formatting with either the 'formatLength' (long, short, medium or full) or 'displayFormat' attributes. By default current locale will be used. Add the following code snippet into the struts.xml file. struts.xml <action name="datetimepickerTag" class="net.struts2.includeTag">    <result>/pages/uiTags/datetimepickerTag.jsp</result> </action> Create an action class as shown: includeTag.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class includeTag extends ActionSupport {   private Date m...

Struts2 - Combobox Tag (Form Tags)

The struts2 combobox is basically an HTML INPUT of type text and HTML SELECT grouped together to give you a combo box functionality. You can place text in the INPUT control by using the SELECT control or type it in directly in the text field. Add the following code snippet into the struts.xml file. struts.xml <action name="comboboxTag" class="net.struts2.comboboxTag">    <result>/pages/uiTags/comboboxTag.jsp</result> </action> Create "comboboxTag " action class and a list in the class and populate it with various items as shown in the class. comboboxTag.java package net.struts2; import com.opensymphony.xwork2.ActionSupport; import java.util.*; public class comboboxTag extends ActionSupport{      private List fruits;   public String execute()throws Exception{   fruits = new ArrayList();   fruits.add("Appl...

Struts2 - Checkboxlist Tag (Form Tags)

In this section, we are going to describe the checkboxlist tag. The checkboxlist tag is a UI tag that creates a series of checkboxes from a list. Setup is like or , but creates checkbox tags. Add the following code snippet into the struts.xml file. struts.xml <action name="checkboxlistTag" class="net.struts2.checkboxlistTag">    <result>/pages/uiTags/checkboxlistTag.jsp</result> </action> Create two lists in the action class and populate them with various items as shown in the " checkboxlistTag " class. 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();...

Struts2 - Checkbox Tag (Data Tags)

In this section, we are going to describe the checkbox tag. The checkbox tag is a UI tag that is used to render an HTML input element of type checkbox, populated by the specified property from the ValueStack. Add the following code snippet into the struts.xml file. struts.xml <action name="checkboxTag">    <result>/pages/uiTags/checkboxTag.jsp</result> </action> Create a jsp using the tag It renders an HTML input element of type chechbox. checkboxTag.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <html>   <head>    <title>Checkbox  (Form Tag) Tag Example!</title>   </head>   <body>   <h1><span style="background-color: #FFFFcc"> Checkbox Tag Example!</span></h1>   <b>Sex</b><br>   <s:checkbox label="Ma...