Solved

jsp method declarations

Posted on 2003-11-21
9
418 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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