Magazine
 
Struts2 Data Tags

Output of paramTag.jsp:

6. Set Tag (Data Tag) Example

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/dataTags/setTag.jsp</result>
</action>

Now create a jsp page using <s:set> 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 <s:set name=”technologyName”
value=”%{‘Java’}”/> 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 Example</title>
</head>
<body>
<h2>Set Tag Example</h2>
<s:set name=”technologyName”
value=”%{‘Java’}”/>
Technology Name: <s:property
value=”#technologyName”/>
</body>
</html>

Output of the setTag.jsp

7. Text Tag (Data Tag) Example
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 Struts2 Data Tags
    Jan-08 Java Jazz Up 49 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.


Jan 2008 | Java Jazz Up | 48
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF