|
Struts2 Data Tags |
|
8. Property Tag (Data Tag) Example
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.javajazzup.propertyTag”>
<result>/pages/dataTags/propertyTag.jsp
</result>
</action>
Create an action class as shown:
propertyTag.java
package net.javajazzup;
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.javajazzup;
public class companyName {
private String name;
public void setName(String name){
this.name =name ;
}
public String getName(){
return name;
}
}
|
|
Create a jsp using the tags.
<s:property value=”%{name}” /> it prints
the result of myBean’s getMyBeanProperty()
method.
<s:property value=”name” default=”Default
Value” /> it prints the result of
companyName’s getName() method and if it
is null, print ‘a default value’ instead.
propertyTag.jsp
<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Property Tag Example</title>
</head>
<body>
<h2>Property Tag Example</h2>
<!— Example to pick the value through bean
class —>
<s:bean
name=”net.javajazzup.companyName”
id=”uid”>
<s:param name=”name”>JavaJazzUp</
s:param>
<s:property value=”%{name}” /><br>
</s:bean>
<!— Default value —>
<s:property value=”name”
default=”Default Value” />
</body>
</html>
Output of the propertyTag.jsp:
|
|
Jan 2008 | Java Jazz Up | 50 |
|
|
|
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 |
|
|
|
|
|
|
|
|
|