You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Axel Seinsche <st...@seinsche.net> on 2004/06/10 15:41:27 UTC
getting a random number with JSTL?
Hi all,
I know this is not a JSTL list, but maybe someone can tell me, if there
is a possibilty to get a random number with a JSTL tag. Best would be to
have min and a max value. If this doesn't exist, I think about wrtiting
such a tag for me. But I don't have to do this, if it still exists. ;-)
Thanks,
Axel
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] getting a random number with JSTL?
Posted by Kris Schneider <kr...@dotech.com>.
Not directly. If you're using JSP 2.0, you can create an EL function to proxy
access to java.util.Random:
<%@ taglib prefix="rand" uri="http://dotech.com/random" %>
<jsp:useBean id="random" class="java.util.Random"/>
${rand:nextInt(random, 10)}
${rand:nextDouble(random)}
Another approach would be to create a JavaBean to proxy access to Random:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<jsp:useBean id="random" class="com.dotech.RandomBean"/>
<c:set target="${random}" property="maxInt" value="10"/>
<c:out value="${random.nextInt}"/>
Or, since this is an MVC framework list, you could generate the random number in
a Filter or an Action and set it as a request attribute so that it's available
to the JSP.
Quoting Axel Seinsche <st...@seinsche.net>:
> Hi all,
>
> I know this is not a JSTL list, but maybe someone can tell me, if there
> is a possibilty to get a random number with a JSTL tag. Best would be to
> have min and a max value. If this doesn't exist, I think about wrtiting
> such a tag for me. But I don't have to do this, if it still exists. ;-)
>
> Thanks,
>
> Axel
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org