File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert string to Integer in JSF code only

 
naveen gupta
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic