• 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

problem on c:set

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My code below,

Bean class



jsp page:


output:

new

Afterwards replacing jsp:setProperty line to c:set below,



output:

javax.servlet.ServletException: Invalid property in <set>: "p"

Why?






[ January 10, 2007: Message edited by: Bob CHOI ]
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using EL to evaluate the bean name solved the problem

<c:set target="${myBean}" property="p" value="new"/>
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"with the target attribute you do not type in the String literal that represents the name under which the attribute was bound to the page, scope, etc. The "target" attribute must have a value that resolves the real thing."

-Head First Bible, Chapter 9 verse 446

So it must be an EL expression, scripting expression, jsp:attribute
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Biba!

What's "jsp:attribute", a standard action? i couldn't find it even in jsp spec. :roll:
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, i do find it after navigating the Spec "slowly", wow! "Automatic" searching "jsp:attribute" in adobe reader leads to nothing.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consider the cas where you hava custom tag called "myAdvice" and it has to mandatory attibutes called "taste" and "colour". Suppose that it has declared <body-content>empty</body-content>. now consider the following code -

<myTag:myAdvice>
<jsp:attribute name="taste">sweet</jsp:attribute>
<jsp:attribute name="colour">amber</jsp:attribute>
</myTag:myAdvice>

its clear from the above example that, jsp:sttribute is a way to set the attributes of your tag, as a BODY, even thoug your tag cant have a body


got it ??
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
refactor c:set below,



Got that exception again...
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also very confused.



It compiles and works.



It compiles and works. But



It does not work! Why? I get an exception:
org.apache.jasper.JasperException: Invalid property in <set>: "p"
 
Biba Basnetti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess Head First was wrong about this.

It seems illegal to set <c:set> tag's TARGET attribute with <jsp:attribute> It doesn't work if you put EL or a scriplet inside the jsp:attribute body. It makes sense though because if you can't even set the target with a string literal variable that has a reference to an object why should you be able to use <jsp:attribute>? Isn't the body of the jsp:attribute tag going to be evaluated to a string literal too?

Here is a good example to show that it's true:


<c:set target="${myBean}">
<jsp:attribute name="property">p</jsp:attribute>
<jsp:attribute name="value">${myBean}</jsp:attribute>
</c:set>



The result:

mybeans.MyBean@13b9fae

So you put the EL ${myBean} in the body of jsp:attribute and assign it to the target attribute, you are assigning "mybeans.MyBean@13b9fae"
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "target" attribute may accept ELed/expressed value when "rtexprvalue" is turned on in tld. "Unforturnately" here it IS the case.
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
let's explore how tag handler classes use setter to deal with attributes.

tag form 1: attribute="name"
converted to: setAttribute(name),
inside the setter, we can code below,

{
name instanceof String?this.value=getValue(name):throw new Exception();
}

tag form 2: attribute="${name}"
converted to: setAttribute(value=getValue(name)),
inside the setter, we can code below,

{
this.value=value;
}

In the handlers we can continue set/get properties of value normally if it is bean object, otherwise an exception is thrown.
[ January 12, 2007: Message edited by: Bob CHOI ]
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go on with "dynamic" attribute a little bit below

tag form 3: dynaAttrName="value"
converted to: javax.servlet.jsp.tagext.DynamicAttributes:setAttribute(namespace,dynaAttrName,value),
inside the setter, we can code below,

{
pageContext.setAttribute(dynaAttrName,value,PageContext.REQUEST_SCOPE);
}

tag form 4: dynaAttrName="${name}"
converted to: javax.servlet.jsp.tagext.DynamicAttributes:setAttribute(namespace,dynaAttrName,value=getValue(name)),
inside the setter, we can code similar to above.
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Bob, I hardly follow your explanations. To put it simple <jsp : attribute > element has its use only with attributes which type is String. Am I right?
Don't you think it is not very useful then?

I observed another strange behaviour regarding attribute standard action.





It works, But:



It does not!
org.apache.jasper.JasperException: <h3>Validation error messages from TagLibraryValidator for c in /SimplePage.jsp</h3><p>18: Encountered illegal body of tag "c:set" tag, given its attributes.</p>

[ January 14, 2007: Message edited by: Jasiek Motyka ]
[ January 14, 2007: Message edited by: Jasiek Motyka ]
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jasiek

jsp:attribute might declare not accepting ELed stuff providing that it had used declarative "rtexprvalue=false".

Howerver the problem on the 2nd code snippet seems strange to me, too.
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jasiek

Sorry, i was mistaked about "rtexprvlaue" - it's all about attribute. The behavior on both code snippets might actually depend on "body-content" setting on c:set and jsp:attribute.

"body-content" has four optional values:
- empty
- scriptless
- jsp
- tagdependant

Therefore, "body-content=tagdependant" could cause them to act "irregually" till we find out how the tag handlers work accordingly.
 
reply
    Bookmark Topic Watch Topic
  • New Topic