Solved

jsp method declarations

Posted on 2003-11-21
9
420 Views
Last Modified: 2010-04-01
Is there a way of  using jsp custom tag in a jsp declaration such as:

<%!
public void pumpOutChildren(IItem currentItem)
{       
%>
<ms:bindings name="currentItem" id="boundItem">
<%=  
   boundItem.getFullName();
%>
</ms:bindings>
<%
}
%>

as this does not appear to work
0
Comment
Question by:danBosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 30 total points
ID: 9798965
I don't think so, as the <ms:bindings bit is outside the <%! bit, and therefore it is invalid in the generated servlet :-(

<%!
public void pumpOutChildren(IItem currentItem)
{      
%>

opens a new method in the generated Servlet, but it has no closing tags...so the JSP won't compile :-(

I hope you see what I mean...

Tim
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9798980
The answer to your question is NO!
because :
The tag needs other environment support that you don't have it in your declared method.
And you cannot mix <%! with <%.

Most of jsp processor will extract all <%! and process first, then the rest.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9799252
yeah...like I said... kinda ;-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:kennethxu
ID: 9801201
sorry, only find that you have your message posted after I post mine.
points to TimYates
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9803271
> sorry, only find that you have your message posted after I post mine.

Hee hee...no worries :-)

I'm new to the JSP TA, and it's nice to see I was right :-)

Hehehe, now to catch you up ;-)

Tim
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9806302
Tim, I have seen that your answers were/are in high quality. I have limited time to support this TA and welcome all experts to contribute. :-)
0
 

Author Comment

by:danBosh
ID: 9809208
so there is no way of doing this, ignore my syntax, i just want to achieve something like that
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9809494
Hmmmm...

You can do:

<%!
public void pumpOutChildren( IItem currentItem )
{      
    out.println( currentItem.getFullName ) ;
}
%>

Not sure that "out" will be valid though...  you might need to do:

<%!
public void pumpOutChildren( IItem currentItem, PrintWriter out )
{      
    out.println( currentItem.getFullName ) ;
}
%>

Then you can call the method from your JSP code:

<%
  pumpOutChildren( item ) ;
%>

or

<%
  pumpOutChildren( item, out ) ;
%>
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9812643
>> i just want to achieve something like that
NO, not custom tag in a jsp declaration.

But you might be able to something similar with <jsp:include>
you put you custom tag in an included jsp page, and in the main page use <jsp:include> when you need to call it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question