| Author |
Question regarding c:set
|
B.Sathish
Ranch Hand
Joined: Aug 18, 2005
Posts: 372
|
|
Can c:set be used to set a property of a bean that has only a getter method for that property? <c:set target="$(person}" property="name" value="abc"/> Assuming there is a "person" attribute in some scope, will this work if the Person class has only a getName() method but not a setName() method? ie it's name property is read-only? Its intuitive to figure out that jsp:setProperty won't work <jsp:setProperty name="person" property="name" value="abc"/> will get translated to person.setName("abc") which won't compile because person does not have a setName method. But what will happen with c:set? will it give an error? Appreciate your responses.
|
 |
Sebastien Col
Greenhorn
Joined: Aug 18, 2005
Posts: 13
|
|
No, your bean must expose a setter for the property you're setting through the <c:set>. I tried with a public property, it doesn't work either. Sebastien
|
 |
B.Sathish
Ranch Hand
Joined: Aug 18, 2005
Posts: 372
|
|
|
Thanks for trying it out and responding Sebastien !!
|
 |
Sehrish Hasan
Ranch Hand
Joined: Aug 15, 2005
Posts: 43
|
|
But I thought a bean is not a bean if it doesnt expose the getter and the setter method both. It shouldnt work because of this reason right??? Would <jsp:useBean id=......> work in this case? I thought it wouldnt if its not exposing the setter method? Please clarify... Thanks, M
|
 |
Sergey Tyulkin
Ranch Hand
Joined: May 10, 2005
Posts: 87
|
|
It's a confusing question.. As far as i remember Java Beans specification requires both setter and getter. But in the JSP/Servlet technology we can use beans, that can setter or getter alone, if the user doesn't use them in opposite way. For example, if the user calls only <jsp:getProperty>, then container (or compiler, or anything) will not complain, if the bean have no setter.
|
 |
 |
|
|
subject: Question regarding c:set
|
|
|