File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes convert string to Integer in JSF code only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "convert string to Integer in JSF code only" Watch "convert string to Integer in JSF code only" New topic
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: 200

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: 16054
    
  21

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: 16054
    
  21

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: 200

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert string to Integer in JSF code only