Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSF Converters #319

Closed
lyahim opened this issue Mar 5, 2016 · 13 comments
Closed

JSF Converters #319

lyahim opened this issue Mar 5, 2016 · 13 comments
Assignees
Labels
Milestone

Comments

@lyahim
Copy link
Contributor

lyahim commented Mar 5, 2016

Hello All,

Can you check the converter operation? At now I try to use a converter for display number with my locale format. I cannot use <f:convertnumer /> because it's cannot display error message(#280) if the number incorrect. Therefore I made a custom converter, but when I submit the form the converter getAsObject method cannot called and I have got the ClassCastException.

I use MyFaces 2.2.9, the response message is:

<partial-response>
<error>
<error-name>javax.faces.component.UpdateModelException</error-name>
<error-message>org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: Cannot convert 3 000 of type class java.lang.String to class java.lang.Float</error-message>
</error>
</partial-response>

Thank you,
Mihaly

@stephanrauh stephanrauh added this to the v0.8.2 milestone Mar 5, 2016
@stephanrauh stephanrauh added the bug label Mar 5, 2016
@stephanrauh stephanrauh self-assigned this Mar 5, 2016
@asterd
Copy link
Collaborator

asterd commented May 2, 2016

Hi @lyahim,
have you re-check if this issue is still present in bootsfaces 0.8.2 snapshot?
Maybe, this problem was already solved with another bug fix, because i've try to reproduce your error with myfaces, native or custom converter, and i haven't found errors..

Can you please do this check?
Thank you!

@stephanrauh: maybe this error was solved with the edit to getValue2Render of CoreRenderer don't you think?

@stephanrauh
Copy link
Collaborator

It doesn't seem to be solved. At least I managed to reproduce #280. I don't know about custom converters, but I've decided to start with the standard converters first.

@asterd
Copy link
Collaborator

asterd commented May 2, 2016

umh.. maybe i've missed something, because i've used custom converter but also f:convertNumber without any problem. The only difference is that i use mojarra...

@stephanrauh
Copy link
Collaborator

Have a look over here: http://www3.bootsfaces.net/Showcase/forms/converters.jsf

Depending on your locale, the number are shown with a decimal comma (in place of the Anglo-Saxon decimal point). If you click on "calculate", the decimal fraction of the numbers gets lost.

@zhedar
Copy link
Collaborator

zhedar commented May 2, 2016

What would you expect other than that? The converter is set to integer only, it will convert the given String into an integer format, therefore truncating the decimal places.
I guess what's missing is a validator in this case, if you wan't an error message if the format is wrong.

@lyahim You said, that you wrote a custom converter, which yielded a ClassCastException. Shouldn't you just wrap that and throw a ConverterException in this case? I'm not sure if the wrapping is actually needed, but that seems how to deal with this kind of input in such a situation. It seems like the Exception is coming from the custom converter.

@stephanrauh
Copy link
Collaborator

@asterd Your change of the CoreRenderer affected the rendering. The problem of #280 (and probably this ticket, too) occurs during the decoding phase.

@stephanrauh
Copy link
Collaborator

@zhedar Good point. Somehow I've missed the integer bit. However, after removing the integer='true' attribute, the actionListener isn't called at all. Just in case you're curious: I've pushed the modified version to the showcase.

@zhedar
Copy link
Collaborator

zhedar commented May 2, 2016

@stephanrauh Well, to be fair I didn't get to run the example again, even with integerOnly="true" the listenter isn't called. Was it actually in the showcase?

I feel kind dumb to say this, but I think we're probably doing something wrong. If you replace the bootsfaces input fields by standard h:inputText, it will yield the exact same result... so it doesn't seem to work that way.
However, using rich component suites like PrimeFaces never stopped me before, because there's always a another component that does the job (e.g. InputNumber). So I actually have to look up, how to use converters now.
Edit: First thing, I forgot about the fact, that I normally just bind to a Number (e.g. double or int) without specifying a converter at all, because JSF already does that. That's probably why I didn't have to use them so much yet. I normally only use converter operations to display values in a specific way, not the other way around.

@zhedar
Copy link
Collaborator

zhedar commented May 2, 2016

OMG. Why didn't I see that: actionLister <--
Fix that and everything will work as it should.
I currently don't see a BootsFaces bug there, what happens in those converters is up to the user, not to us, isn't it?

Also if conversion fails, there is a message an the label is colored red. So this is also working correctly. Just test that by entering 'a'. But it seems like JSF takes values like 1000 asdasd as 1000, but again that's a JSF issue and can be fixed by using custom converters. If they throw ConverterExceptions, if anything goes wrong, it should be reflected in the UI.

Edit: Just fixed that misspelling, so the showcase now works fine for me as well.

@stephanrauh
Copy link
Collaborator

Oops... I know I was tired yesterday, but I wasn't aware my Eclipse was tired, too...

@stephanrauh
Copy link
Collaborator

I'd like to add some documentation and several example of both custom and standard converter. Plus, I'd like to check if <b:selectOneMenu /> now copes with custom converters. But I'm positive we can close this bug soon.

@zhedar
Copy link
Collaborator

zhedar commented May 3, 2016

Having several converter examples will let us test this quickly in the future and provides further documentation, so that sounds great. I normally use Omnifaces' SelectItemsConverter with selectOneMenus, so maybe we could just check if that one works.

@zhedar zhedar mentioned this issue May 7, 2016
@stephanrauh
Copy link
Collaborator

Let's open a follow-up ticket to document the converters more thoroughly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants