Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is there a way to call tags from within JSP scriptlet methods?  RSS feed

 
Bob Hager
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

Here is the snippet that I need help with:

<%!
public void method1 (String x, String y) {
String z = method2();
doComplexStuff(x, y, z);
}
%>

method1 is being called from numerous places in this (very) large JSP
file. I need to replace the doComplexStuff() method with a custom tag
that looks something like this:

<xyz:doComplexStuffTag x="value1" y="value2" z="value3" />

Is there a way to replace the fourth line, i.e the doComplexStuff
(x,y,z) call, with the mentioned tag without breaking method1() ? Of
course I still need to continue passing the method parameters (x, y
and z) as tag attribute values.

I know I should refactor the whole thing, but this is not practical at
the moment.

Thanks for any pointers..

- Bob
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it will not work that way, as your doComplexStuffTag and method1() will become instance method of finally generated servlet for this jsp. So x, y, z of method1() will not be available to doComplexStuffTag() as x,y,z are local to method1() instance method.



Now for simple parameters:


see generated servlet for this jsp:

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just the fact that you asked this tells me that you're not grokking custom tags. Why use a scriptlet at all for the re-used code -- that's what custom tags are for!
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you make a tag for method1 and then make another tag for doComplexStuff?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!