• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to assign a number to the bean define tag?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to assign a number to a bean like this

<bean efine id="myId" type="java.lang.Integer" value="100" />

and it gives me a run time error for NULL value. what's wrong with this?

Appreciate your help.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSTL is really much better for this sort of thing. I'd use <c:set var="myId" value="100" /> Because JSTL can make on-the-fly conversions between strings and numbers, I can use this as either a string or a number. For example:

<c:out value="${myId + 1}" /> renders 101
<c:out value='${"xyz" + myId}' /> renders xyz100

To answer your original question: except for java.lang.String, which is the default type, creating a bean with <bean:Define> only works where the bean has a no-args constructor. java.lang.Integer is an immutable object, and both its constructors require an argument. That's why your code doesn't work.
[ July 14, 2005: Message edited by: Merrill Higginson ]
 
brucedd tangdd
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot, Merrill. Understanding the underlying reason is even better than getting the solution.

I'll use some alternatives then. Thanks

bruce
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic