| Author |
convert string to Integer in JSF code only
|
naveen gupta
Ranch Hand
Joined: Apr 12, 2006
Posts: 129
|
|
can i use following
sortBy="#{Integer.parseInt(custprofile.storeNo)}"
It's giving me error. But how do i resolve it. I need to do conversion at display time only and NOT in java code
|
 |
Guy deLyonesse
Ranch Hand
Joined: Apr 12, 2011
Posts: 189
|
|
The problem with this code is that the EL needs to reference an instance of a Java Bean and it looks like you're referencing the static class Integer.
Why do you need to avoid putting the solution in the Java code?
|
 |
David Lidz
Greenhorn
Joined: Mar 30, 2011
Posts: 14
|
|
I would suggest using Javascript as if you want a pure client side solution.
The code example you gave will send a request to the server.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
It's unnecessary. EL is automatically going to convert, since the web page isn't binary, it's text. So all that's required is:
Actually, in this case, a property binding is being set up, but EL handles that automatically as well. So no explicit conversion needed.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
Oh wait a minute. Is this what you're trying to address? http://www.coderanch.com/t/534046/JSF/java/sortby
What you actually need is a Comparable interface on the Model object in the backing bean. Or you could front the current model with a façade model whose storeNo field is an integer instead of String.
|
 |
naveen gupta
Ranch Hand
Joined: Apr 12, 2006
Posts: 129
|
|
I have changed below statement, which was giving parsing error while page rendering
sortBy="#{Integer.parseInt(custprofile.storeNo)}"
TO below statement
sortBy="#Integer.parseInt{custprofile.storeNo}" which didn't give me error
But before i can test if it sorts or it really works, i am stuck with other issues with web services security. If above one works i will update
|
 |
naveen gupta
Ranch Hand
Joined: Apr 12, 2006
Posts: 129
|
|
i should have read your comments clearly before replying. Anyway, it's not working
And now coming to the point. Changing the value to Integer is lot of work on the java code.
I think, we can't convert string to integer in the JSF for the SortyBy attribute
let me think
|
 |
Guy deLyonesse
Ranch Hand
Joined: Apr 12, 2011
Posts: 189
|
|
|
As Tim Holloway said, the EL will convert the value into a String for you without having to do so in the backing bean's Java code. All you need to do is make sure there's a public int getStoreNo() method in your class.
|
 |
naveen gupta
Ranch Hand
Joined: Apr 12, 2006
Posts: 129
|
|
yeah, i just changed the type from String to Integer. It was not actually that much of code change
it's one of the field of web service request. on web service it has defined it as String, so i have also had it as String
now i changed it to Integer and doing parsing while i get the results back from web service response
|
 |
 |
|
|
subject: convert string to Integer in JSF code only
|
|
|