• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c:set target

 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friends,
i tried this

<jsp:useBean id="beans" class="model.BookDB"/>

<c:set target="${beans}" property="name" value="mallika"/>

<c ut value="${beans.name}"/>

My question is:-
i tried using target=${model.BookDB} but it didnt work.
Then i tried target="${beans}" and it worked.
Should target=id ??
As in HF book it says,"dont put the "id" name of the attribute here .Page 446(with a body)
It needs a value that resolves toa real thing..

Then according to this what shoul dbe the target?
Is the thing i am doing is wrong??

thanks,
mallika
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mallika shah:
As in HF book it says,"dont put the "id" name of the attribute here .Page 446(with a body)
It needs a value that resolves toa real thing..



Imagine your bean has been created and set as a request (or any other scope's) attribute named "myBean". What you cannot do is:
<c:set target="myBean" property="name" value="mallika"/>

Because "myBean" is not an object, just the attribute name that 'refers' to that object. But you could use EL to get the real object: target="${myBean}".

The JSP code you pasted is alright because:
1) <jsp:useBean id="beans" class="model.BookDB"/> creates a model.BookDB object (the bean) with name "beans" (aka the attribute name) in page scope IIRC.
2) <c:set target="${beans}" property="name" value="mallika"/> is fine because ${beans} evaluates to the object itself (print ${beans} in your page and you will get the model.BookDB.toString() result printed out: something like @09874A, the default toString() method if you did not override it in your bean's class).

I hope I did not complicate things even more :-)
[ April 03, 2007: Message edited by: Sergio Tridente ]
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the jsp source generated for the EL expression might help too
 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sergio,
It was really a nice explanation..

Thanks anupama,looked at the generated java file as well to understand.it helps..

mallika
 
reply
    Bookmark Topic Watch Topic
  • New Topic