You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tobias Eriksson <to...@comopt.com> on 2004/08/17 13:46:34 UTC

how do I call a function in a bean the easy an tidy way?

Hi
 I'm trying to call a method in a BEAN that returns an array of objects
that I need to enumerate on my page. But I don't want to access a
property with EL, like this e.g. ${mybean.names} ) as I need to provide
an argument to the method. I need to say how many names I would like, so
the only thing I could come up with was this;

<c:set var="names" value="<%= mybean.getNames( Integer.parseInt(
request.getParameter("total") )  ) %>" />

Now this looks a bit cumbersome and I was thinking if anyone knew of a
better way of doing this. For example 
	${ mybean.getNames(request.getParameter("total") ) }
would have been nicer and tidier. 

Regards
 Tobias

-----Original Message-----
From: Andy Eastham [mailto:andy@peakdrive.com] 
Sent: Tuesday, August 17, 2004 10:11
To: 'Tomcat Users List'; krawietz@hrs.de
Subject: RE: understanding web.xml

Also look at the sample chapter at http://www.moreservlets.com/

Andy

> -----Original Message-----
> From: Thilo Krawietz [mailto:thilo.krawietz@hrs.de]
> Sent: 17 August 2004 08:07
> To: Tomcat Users List
> Subject: Re: understanding web.xml
> 
> Hi Tobias,
> 
> in Suns official Servlet specification all elements of web.xml are
> explained widely, so i would suggest, that you study this one. You can
> get it here:
> 
> http://java.sun.com/products/servlet/download.html
> 
> Hope this helps & regards,
> 
> Thilo
> 
> 
> Tobias Eriksson wrote:
> 
> >Hi
> > I have been searching the web some for information about how to
> >configure / setup; web.xml, but haven't really found anything. I
thought
> >there would be something in the TOMCAT documentation, perhaps I
wasn't
> >to thorough when I browsed through it. Does anyone have a link to
some
> >tutorial or article that explains the web.xml?
> >
> >Regards
> > Tobias
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: how do I call a function in a bean the easy an tidy way?

Posted by QM <qm...@brandxdev.net>.
On Tue, Aug 17, 2004 at 01:46:34PM +0200, Tobias Eriksson wrote:
:  I'm trying to call a method in a BEAN that returns an array of objects
: that I need to enumerate on my page. But I don't want to access a
: property with EL, like this e.g. ${mybean.names} ) as I need to provide
: an argument to the method.

What about a small redesign (Page Controller, MVC, whatever) such that
all parameter handling is done within a servlet that dispatches to the
JSP for display?

Clean design calls for using JSPs just for presentation; they should
have to do just enough logic to format the data they've been given.

Once you have to pass a numeric parameter to a method, you must concern
yourself with bounds checking; in turn, you must handle errors, which
leads to its own can of worms.

-QM

-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: how do I call a function in a bean the easy an tidy way?

Posted by Christian Fritze <Th...@sprawl.de>.
Tobias Eriksson wrote:
> Hi
>  I'm trying to call a method in a BEAN that returns an array of objects
> that I need to enumerate on my page. But I don't want to access a
> property with EL, like this e.g. ${mybean.names} ) as I need to provide
> an argument to the method. I need to say how many names I would like, so
> the only thing I could come up with was this;
> 
> <c:set var="names" value="<%= mybean.getNames( Integer.parseInt(
> request.getParameter("total") )  ) %>" />

<%= mybean.somemethod() %>

won't give you an array anyway. <%= %> returns only strings.

IMHO you *have* to do something like this:

<%
    String [] rectypesincurrentquery = currentQuery.getRectype();
    out.println("<p><b>currentQuery.getRectype() returns</b><br />");
    for (int i = 0; i < rectypesincurrentquery.length; i++) {
%>
      <%= i + ": " + rectypesincurrentquery[i] + "<br />" %>
<%
    }
%>


greetings
Christian


-- 
Grüße aus Europas größtem       Greetings from Europe's largest
Urban Sprawl (DUDOMA -- Duisburg Dortmund Metropolitan Axis ;-)
Christian Fritze   <Th...@sprawl.de>   http://www.sprawl.de/


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: how do I call a function in a bean the easy an tidy way?

Posted by Cott Lang <co...@internetstaff.com>.
I don't know of any easy tidy way, unless you're using Resin, which
allows you to call functions that don't match bean naming conventions
and pass parameters.  It's always nice to have standards to protect us
from ourselves. :)

There is a more tidy way - define a function in a .tld.  Since it has to
be static, you may end up writing a static class just to call the
function. 

http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag-p2.html



On Tue, 2004-08-17 at 04:46, Tobias Eriksson wrote:
> Hi
>  I'm trying to call a method in a BEAN that returns an array of objects
> that I need to enumerate on my page. But I don't want to access a
> property with EL, like this e.g. ${mybean.names} ) as I need to provide
> an argument to the method. I need to say how many names I would like, so
> the only thing I could come up with was this;
> 
> <c:set var="names" value="<%= mybean.getNames( Integer.parseInt(
> request.getParameter("total") )  ) %>" />
> 
> Now this looks a bit cumbersome and I was thinking if anyone knew of a
> better way of doing this. For example 
> 	${ mybean.getNames(request.getParameter("total") ) }
> would have been nicer and tidier. 
> 
> Regards
>  Tobias
> 
> -----Original Message-----
> From: Andy Eastham [mailto:andy@peakdrive.com] 
> Sent: Tuesday, August 17, 2004 10:11
> To: 'Tomcat Users List'; krawietz@hrs.de
> Subject: RE: understanding web.xml
> 
> Also look at the sample chapter at http://www.moreservlets.com/
> 
> Andy
> 
> > -----Original Message-----
> > From: Thilo Krawietz [mailto:thilo.krawietz@hrs.de]
> > Sent: 17 August 2004 08:07
> > To: Tomcat Users List
> > Subject: Re: understanding web.xml
> > 
> > Hi Tobias,
> > 
> > in Suns official Servlet specification all elements of web.xml are
> > explained widely, so i would suggest, that you study this one. You can
> > get it here:
> > 
> > http://java.sun.com/products/servlet/download.html
> > 
> > Hope this helps & regards,
> > 
> > Thilo
> > 
> > 
> > Tobias Eriksson wrote:
> > 
> > >Hi
> > > I have been searching the web some for information about how to
> > >configure / setup; web.xml, but haven't really found anything. I
> thought
> > >there would be something in the TOMCAT documentation, perhaps I
> wasn't
> > >to thorough when I browsed through it. Does anyone have a link to
> some
> > >tutorial or article that explains the web.xml?
> > >
> > >Regards
> > > Tobias
> > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > >
> > >
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org