• 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

Question on c:set target=""

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HFSJ on page 447 I am not able to understand what value is valid for target object.Here I am pasting the info as is on page 447

The target is for putting in an expression that resolves to the real object.If you put in a string literal that represents the "id" name of the bean or Map,it won't work.In other words "target" is not for the attribute name of the bean or map --- it's for the actual attribute object.



How can we reffer to the actual attribute ??? Can anyone please explain with an example by comparing what we set using setAttribute and what value is given in target?

Thanks
Veema
[ March 20, 2006: Message edited by: Veena Point ]
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are talking about a java-object stored as an "Attribute" in any of the scopes. So you can use a EL like this

<c:set targer="${javaObject} property="color" value="blue" />

In this line you are saying to the container to search in all scopes
for an attribute called javaObject but in fact the attribute is a reference
to a real java-object. So the code above is equivalent to say in java:


pageContext.findAttribute("javaObject").setColor("blue");

Somehow the container does the appropiate casting.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What they mean by actual attribute object?even in jsp:usebean we use actual attribute object name? Does this mean the following?

Person p new Person();
p.setName("Test");
request.setAttribute("person"p);

<C:target target="person" property="name" value = "TestAgain">

in the above code target should be reffering to person as it will in id of jsp:useBean ?
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK if you have this:

Person p new Person();
p.setName("Test");
request.setAttribute("person"p);

and you do this
<C:target target="person" property="name" value = "TestAgain">

I think is equivalent to this java code:

person.setName("TestAgain");

But "person" does not have a valid reference at this point to anything. So it will throw exception.

But if you put this:

<c:target target="${person}" property="name" value = "TestAgain">

should be equivalent to this

pageContext.findAttribute("person").setName("TestAgain");

This should work provided the attribute "person" exist in any of the 4 scopes.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.I understood to some extent.I tried the following code

Person p = new Person();
p.setName("TestName");
request.setAttribute("person",p);
%>
<%= p.getName()%>

<c:set target="${person}" property = "name" value = "MyTestNameAgain"/>

<%= p.getName()%>

it prints TestName TestName

it is not printing TestName MyTestNameAgain !
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's weird I think your code it should work.

You may try playing around with <jsp:useBean> or <jsp:getProperty> and see what you get. for the same code.

I will try that tonight and see what I get.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think you have not included the core tag library in your JSP. Include Standard tag library using

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> at the top of your page.It should give the proper result.

Thanks
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah ,I forgot to include taglib.

Thank you all.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic