Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use <bean:write > tag in strut 1.2?

Tags:

java

struts-1

How to Use <bean:write> tag in Struts 1.2.

In name attribute, what value have to be used? Is bean name your property name?

like image 470
sachin Avatar asked Jul 14 '11 12:07

sachin


People also ask

What does bean write tag do?

Javadoc for <bean:write> : Specifies the attribute name of the bean whose property is accessed to retrieve the value specified by property (if specified). If property is not specified, the value of this bean itself will be rendered.


2 Answers

Javadoc for <bean:write>:

Specifies the attribute name of the bean whose property is accessed to retrieve the value specified by property (if specified). If property is not specified, the value of this bean itself will be rendered.

In essence, if you have a JavaBean (with getters and setters),

Person person = new Person;
request.setAttribute("person", person);

by setting <bean:write name="person" property="age" />, you're telling Struts to first find person object first from PageContext scope. If not found, then request, then session, then application scope.

The property="age" attribute (from <bean:write /> tag), will then call the getter method getAge() from the Person object (irrespective of whether there's an instance variable called age on the bean).

Hope this helps.

like image 50
Buhake Sindi Avatar answered Sep 25 '22 08:09

Buhake Sindi


In order to display person.getAge() you would use

<bean:write name="person" property="age" />
like image 36
Vlad Avatar answered Sep 21 '22 08:09

Vlad