| Author |
params in jsp:setProperty in .tag file won't accept el
|
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
I know the tag is actually loading because it's printing out the Test, the Hi and correctly filling in whatever I put into the prefix attribute. However, it's not setting the attributes in the bean. What in the sam hill? Why won't this work?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
Is the property mutator being called? If so, what value is being passed to it?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
The mutator is not being set. I did some experiments. I can: a. Set a jsp:setProperty directly in the jsp at the place where I previously used the tag (right after the jsp:useBean) b. Set the jsp:setProperty directly in the tag (ie, not using el in the param, just setting the param directly) c. Inside the .tag file, I can output the value that I pass into the prefix attribute However, when I try to set information in the jsp:setProperty's param attribute in the .tag file, and that information I want to set comes from the .tag file's attribute, it doesn't work. Does this mean you can't set the attributes of markup inside tags using expression language? [ September 21, 2006: Message edited by: Jacob Fenwick ] [ September 21, 2006: Message edited by: Jacob Fenwick ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
Where is mybean set up?
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
|
I'm instantiating mybean using a jsp:useBean in the jsp that calls this tag. I know that I can access both from the parent jsp page and from within the .tag file from experiments a and b.
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
Here is a more concise example of the problem with all the code: TestBean.java test.tag tagtest.jsp The html output I get when I call tagtest.jsp?footable=test is: And the Tomcat output is: If anyone has any insight into this let me know. Maybe .tag files can't access the bean somehow?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
Is the "Setting table" diagnostic being emitted? [ September 25, 2006: Message edited by: Bear Bibeault ]
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
No it's not, so somehow the reflection is failing when the jsp:setProperty is called in test.tag. [ September 25, 2006: Message edited by: Jacob Fenwick ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
Then the problem is clearly not in the EL but in the setProperty. That's where you'll need to dig. By the way, why are you using setProperty rather than <c:set>? I haven't used setProperty in years.
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
I realized that the jsp:setProperty is being called first, then the EL is being evaluated. I confirmed this by calling tagtest.jsp this way: This produced the correct html output. I'm trying to rewrite the jsp:setProperty to use a c:set but I'm a little stuck. This is what I have: I need to find a way to concatenate the prefix attribute and some string together, and append that to the param. . I don't think there's a way to do that, so I'll probably have to abandon doing this in a .tag file. I see this as a weakness of c:set. If I had stuck to scriptlets and jsp:setProperty I would have had more control (or maybe not, maybe the jsp:setProperty is called even before the scriptlets).
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
I need to find a way to concatenate the prefix attribute and some string together,
${prefix}someString
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
That won't work. What I'm trying to do is something like this: I know that won't work but that's approximately what I want to do. I want to fill the value of the c:set with the request parameter called prefix+table. So if I pass foo into the prefix attribute of that .tag file then the request parameter will be footable. I don't think this will actually be possible.
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1002
|
|
Of course it is possible. The jsp:setProperty tag wouldn't work, because the "param" attribute will not accept runtime expressions. I'm pretty sure it would just pass the value through as a string without evaluating it. For the JSTL, I think you will have to do it in two steps 1 - generate the parameter name 2 - set the value
|
 |
Jacob Fenwick
Ranch Hand
Joined: Apr 28, 2006
Posts: 55
|
|
Hooray! Thanks Bear, Stefan.
|
 |
 |
|
|
subject: params in jsp:setProperty in .tag file won't accept el
|
|
|