Link to home
Start Free TrialLog in
Avatar of danBosh
danBoshFlag for United Kingdom of Great Britain and Northern Ireland

asked on

jsp method declarations

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
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kennethxu
kennethxu

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.
yeah...like I said... kinda ;-)
sorry, only find that you have your message posted after I post mine.
points to TimYates
> 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
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. :-)
Avatar of danBosh

ASKER

so there is no way of doing this, ignore my syntax, i just want to achieve something like that
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 ) ;
%>
>> 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.