-
Notifications
You must be signed in to change notification settings - Fork 101
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
java.lang.NumberFormatException #713
Comments
I realized that the error occurs when I use a Before the new version, it did not call my converter (ColaboradorConverter.java), and now started calling. But the "value" parameter of the "getAsObject" method is coming as "com.mesure.model.Colaborador@23" instead of just "23", and in the "new Long (value)" command the error occurs. <b:column span="3">
<b:selectOneMenu label="Colaborador" value="#{programacaoExecucaoBean.filtroColaborador}" fieldSize="sm"
process="@this" update="programacoesTable btn-incluir">
<f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{programacaoExecucaoBean.colaboradores}" var="cl" itemLabel="#{cl.nome}" itemValue="#{cl}" />
</b:selectOneMenu>
</b:column> Method in ColaboradorConverter.java: @Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Colaborador retorno = null;
if (StringUtils.isNotEmpty(value)) {
retorno = colaboradorRepository.porId(new Long(value));
}
return retorno;
} If I delete the converter class (ColaboradorConverter.java) from my project, the error no longer occurs. So I don't need converter in this case? |
Class ColaboradorConverter: @FacesConverter(forClass = Colaborador.class)
public class ColaboradorConverter implements Converter {
@Inject
private ColaboradorRepository colaboradorRepository;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Colaborador retorno = null;
if (StringUtils.isNotEmpty(value)) {
retorno = colaboradorRepository.porId(new Long(value));
}
return retorno;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value != null) {
Colaborador colaborador = (Colaborador) value;
return colaborador.getId() == null ? null : colaborador.getId().toString();
}
return "";
}
} |
But I need the converter when I call my form passing the collaborator by parameter, for example: http://localhost:8080/Mesure/colaboradores/CadastroColaborador.xhtml?colaborador=3 In CadastroColaborador.xhtml: ...
xmlns:o="http://omnifaces.org/ui"
... ...
<f:metadata>
<o:viewParam name="colaborador" value="#{cadastroColaboradorBean.colaborador}" />
</f:metadata>
... I realized that <b: selectOneMenu> (Bootsfaces) doesn't have the attribute "convert", But <p:selectOneMenu> (Primefaces) has. Can I configure so that <b: selectOneMenu> does not use converter? That way I can keep my ColaboradorConverter.class for when I call the form with parameter. |
Have you tried setting the That worked on 1.0.2 since BootsFaces didn't allow to use converters on SelectOneMenu components (it uses a generic one). You have multiple options here:
|
Hi @ggam I think your suggestion to change the @FacesConverter and the viewParam would be better in my case. But I have a question: in the current version of BootsFaces does the SelectOneMenu component still use a generic converter? If so, I don't need to create a specific converter for each class, because by default all classes will work with SelectOneMenu, correct? Thanks. |
Yes, AFAIK what BootsFaces has now is something like the OmniFaces generic
converter. It just stores the position of the object in the array, and
sends that to the server.
Until 1.1.0, SelectOneMenu didn't support custom converters. But now that
it does, it's detecting your converter (since you set the forClass
property) and using it. But your converter expects a long, while you are
sending the entire object.
Removing forClass will disable that autodetection. But I still think you
just need to change the itemValue property. Have you tried that already?
El jue., 20 de abril de 2017 18:38, ruanfelisky <notifications@github.com>
escribió:
… Hi @ggam <https://github.com/ggam>
I think your suggestion to change the @FacesConverter and the viewParam
would be better in my case.
But I have a question: in the current version of BootsFaces does the
SelectOneMenu component still use a generic converter? If so, I don't need
to create a specific converter for each class, because by default all
classes will work with SelectOneMenu, correct?
Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#713 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACAucOY8NCji8cpysTZiwJ8dpNoFFcQPks5rx4oHgaJpZM4NC572>
.
|
Ok I got it. I haven't tried changing the itemValue property yet, but I think it would be better to change the conversor/viewParam, because in this case, I only use the converter when I need, right? Tks. |
I've added a few lines to the documentation because it's sort of a breaking change. Is it OK to close the ticket? |
Hi, |
BootsFaces doesn't support this because I simply didn't know about In the meantime, I've implemented converters, but only the old syntax ( |
After upgrading to the latest 1.1.0-SNAPSHOT version, on my screens I'm getting some errors like these below:
Javax.faces.FacesException: java.lang.NumberFormatException: For input string: "com.mesure.model.Veiculo@24"
Java.lang.NumberFormatException: For input string: "com.mesure.model.Colaborador@26"
It sounds like something related to my converter, but I have not changed them recently. This started after the last version 1.1.0-SNAPSHOT
The text was updated successfully, but these errors were encountered: