|
Struts 2 Non-form Tags (UItags) |
|
</s:div>
</body>
</html>
Output:
3. Fielderror Tag (Non-Form UI Tags)
Example
The fielderror tag is a UI tag that renders field
errors if they exist.
Add the following code snippet into the
struts.xml file.
struts.xml
<action name=”fieldError”> <result>/
pages/nonformTags/loginFielderrorTag.jsp</
result>
</action>
<action name=”checkUser”
class=”net.javajazzup.CheckField”>
<result name=”input”>/pages/
nonformTags/loginFielderrorTag.jsp</result>
<result name=”error”>/pages/nonformTags/
|
|
fielderrorTag.jsp</result>
<result>/pages/nonformTags/
validuser.jsp</result>
</action>
Develop an action class using
addFieldError(String fieldName, String
errorMessage) method. This method adds an
error message for a given field to the
corresponding jsp page.
CheckField.java
package net.javajazzup;
import
com.opensymphony.xwork2.ActionSupport;
public class CheckField extends ActionSupport
{
private String username = null;
private String password = null;
public String execute() throws Exception{
if ((getUsername().equals(“javajazzup”))
&&
(getPassword().equals(“javajazzup”))){
addActionMessage(“Valid User!”);
return SUCCESS;
}
if(!(getUsername().equals(“javajazzup”)))
addFieldError(“username”,”Invalid
username!”);
if(!(getPassword().equals(“javajazzup”)))
addFieldError(“password”,”Invalid
password!”);
return ERROR;
}
//Set and get the user name
public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return username;
}
//set and get the password
public void setPassword(String pass){
password = pass;
}
public String getPassword(){
|
|
Mar
2008 | Java Jazz Up |32 |
|
|
|
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,
Download PDF |
|
|
|
|
|
|
|
|
|