Struts 2 Bean Tag Example

作者: admin
发表于: 1970-1-1 08:33:31
    

We will see how the bean tag works using a currency converter example. In this example we will convert dollars to rupees. We do this using the CurrencyConverter JavaBeans class.

The CurrencyConverter class.
 
01.package vaannila;
02. 
03.public class CurrencyConverter {
04. 
05.    private float rupees;
06.    private float dollars;
07. 
08.    public float getRupees() {
09.            return dollars * 50;
10.    }
11.    public void setRupees(float rupees) {
12.            this.rupees = rupees;
13.    }
14.    public float getDollars() {
15.            return rupees/50 ;
16.    }
17.    public void setDollars(float dollars) {
18.            this.dollars = dollars;
19.    }
20. 
21.}
The next step is to create an instance of the CurrencyConverter bean in the jsp page using the bean tag. We can either use the bean tag to push the value onto the ValueStack or we can set a top-level reference to it in the ActionContext. Let's see one by one.

First we will see how we can do this by pushing the value onto the ValueStack. The index.jsp page contains the following code.

01.<html>
02.<head>

  1  2  3  下页

已有0条评论,点击查看
 
 9  顶一下
 7  踩一下
 Struts 2 UI Tags Tutorial
 已经是最后一篇
发表评论

  

  广州IT吧 | 设置底部链接
© 2012 | 设置底部链接
(网站备案号)