how to use <bean:write > tag in strut 1.2?
Solution 1
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.
Solution 2
In order to display person.getAge()
you would use
<bean:write name="person" property="age" />
sachin
Updated on July 17, 2022Comments
-
sachin almost 2 years
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? -
Vlad almost 13 years+1 for detailed explanation -1 for confusing a bit the scope lookup order: it's
page
,request
,session
thenapplication
-
Buhake Sindi almost 13 years@Vlad, thanks for finding my mistake. I've edited to fix the errors.
-
Arun almost 10 yearsTHanks for explaining :) +1 for Explanation
-
aman_novice over 6 yearsnow, in case if i want to use "age" property again, how will i retrieve the value? Is that possible? My scenario is, on click of button b1, i fetch certain value, let us say "age" and populate it on the jsp page using
<bean:write name="person" property="age"/>
If I press another button b2, I am not able to get the value from this age property. form.getAge() returns null where 'form' is of type Person.