• Post Reply Bookmark Topic Watch Topic
  • New Topic

forEach dynamic end value  RSS feed

 
wbrian radley
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,

I'm trying to do something that must be very common but I haven't found a solution after some research.
each option should a year, ex. 2010;
the code below does output the year correctly;
what I need is be able to calculate the end as: ${beanResponse.year} + 10
I know an expression is written as: ${ 2010 + 10};
the question then is: how to substitute 2010 with a variable?

thank you for any assistance that you might be able to provide
B


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to properly indent your code when posting to the forums. Thanks.

wbrian radley wrote:
I know an expression is written as: ${ 2010 + 10};
the question then is: how to substitute 2010 with a variable?

Assuming that by variable you mean a scoped variable (and not a scripting variable, which is invalid):
 
wbrian radley
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried:


where beanResponse is set in the session and the value of year is 2010 and year an int not a String

and the error was:
Cannot convert {2010+ 10} of type class java.lang.String to class java.lang.Integer

so the next question is how to convert from string to integer;
I'm well aware of the Integer and String functions
but I'd rather not guess

B
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wbrian radley wrote:I tried:

Not even close to valid syntax. Did you not see my reply above?

so the next question is how to convert from string to integer;

No, it's not.

Get the syntax right.
 
wbrian radley
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you not see my reply above?

ofcourse I did and it's equally obvious that I'ved missed the proper interpretation.
insults are never helpful.

the variableName is beanResponse.year

substituting directly:

yields a NumberFormatException

B
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wbrian radley wrote:insults are never helpful.
Neither is seeing insults where none exist. It was a question.

substituting directly:

yields a NumberFormatException

What is the type of beanResponse.year?
 
wbrian radley
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from the class:


in the following beanRespose.year is not evaluated:

the error message is:
Cannot convert {beanResponse.year + 10} of type class java.lang.String to class java.lang.Integer


in the following - as wrong as it is - beanResponse.year is evaluated:

the error message is:
Cannot convert { 2010+ 10} of type class java.lang.String to class java.lang.Integer

beanResponse is stored in the session:


B
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wbrian radley wrote:in the following beanRespose.year is not evaluated:

You forgot the $.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!