0

How to resolve the jsf datatable java.lang.NumberFormatException: For input string, in bellow my code : I have SelectItemDTO :

                public class SelectItemDTO implements Serializable {
                private static final long serialVersionUID = 1L;
                private Object value;
                private String label;
                public SelectItemDTO() {
                }
                public SelectItemDTO(Object value, String label) {
                    this.value = value;
                    this.label = label;
                }
                public Object getValue() {
                    return value;
                }
                public void setValue(Object value) {
                    this.value = value;
                }
                public String getLabel() {
                    return label;
                }
                public void setLabel(String label) {
                    this.label = label;
                }

            }

in my dialog.xhtml i have :

                 <p:dialog id="#{cc.attrs.widgetVar}" widgetVar="#{cc.attrs.widgetVar}" resizable="true" responsive="true" modal="true" appendTo="@(body)" height="580" width="850" dynamic="true">
                    <h:form>
                        <p:fieldset>
                            <p:panel header="Ajout d'une nouvelle règle">
                                #{cc.attrs.value.parametres}
                            </p:panel>
                        </p:fieldset>
                    </h:form>
                  </p:dialog>

when i run my application i have the output in dialog.xhtml [com.sfr.medusa.dto.SelectItemDTO@1d591889, com.sfr.medusa.dto.SelectItemDTO@62e36383]

now when i change the dialog to :

    <p:dialog id="#{cc.attrs.widgetVar}" widgetVar="#{cc.attrs.widgetVar}" resizable="true" responsive="true" modal="true" appendTo="@(body)" height="580" width="850" dynamic="true">
            <h:form>
                <p:fieldset>
                    <p:panel header="Ajout d'une nouvelle règle">
                        <p:dataTable value="#{cc.attrs.value.parametres}" var="par" emptyMessage="#{msg['datatable.msg.empty']}">
                                <p:column headerText="Param">
                                    <h:outputText value="#{par.label}" />
                                </p:column>

                                <p:column headerText="Value">
                                    <h:inputText value="#{par.value}" />
                                </p:column>
                        </p:dataTable>
                    </p:panel>
                </p:fieldset>
            </h:form>
    </p:dialog>

I have a an exception:

            java.lang.NumberFormatException: For input string: "parametres"
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
            at java.lang.Integer.parseInt(Integer.java:580)
            at java.lang.Integer.parseInt(Integer.java:615)
            at javax.el.ListELResolver.coerce(ListELResolver.java:157)
            at javax.el.ListELResolver.getValue(ListELResolver.java:70)
            at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
            at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
            at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
            at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
            at com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:158)
            at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
            at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
            at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
            at javax.faces.component.UIData.getValue(UIData.java:732)
            at org.primefaces.component.api.UIData.getDataModel(UIData.java:764)
            at org.primefaces.component.api.UIData.setRowModel(UIData.java:571)
            at org.primefaces.component.api.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:564)
            at org.primefaces.component.api.UIData.setRowIndex(UIData.java:473)
            at javax.faces.component.UIData.invokeOnComponent(UIData.java:1041)
            at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503)
            at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:718)

with this code i get the expected result but not with datatable:

           <p:panelGrid class="ui-noborder" columns="2" cellpadding="5">
                    <f:facet name="header">
                        <p:row>
                            <p:column headerText="Paramètre" />
                            <p:column headerText="Valeur" />
                        </p:row>
                    </f:facet>
                    <c:forEach items="#{cc.attrs.value.parametres}" var="param">
                        <p:row>
                            <p:column>
                                <p:outputLabel value="#{param.label}" />
                            </p:column>
                            <p:column>
                                <p:inputText value="#{param.value}" />
                            </p:column>
                        </p:row>
                    </c:forEach>
                </p:panelGrid>                      
Gogo
  • 292
  • 8
  • 19

3 Answers3

0

I have the same exception with other component :

     <p:commandButton icon="ui-icon-check" value="#{msg['btn.add']}" onstart="PF('statusDialog').show()" oncomplete="PF('#{atWidgetVar}').hide();" actionListener="#{cc.attrs.actionListener}" update="#{cc.attrs.update}" >
        </p:commandButton>

this code cause the same exception. when i replace update attribute with :

 <f:ajax render="#{cc.attrs.update}"/>

this one work fine.

i think the primefaces datatable have many bugs when the datatable is empty.

Gogo
  • 292
  • 8
  • 19
0

Ok i found it (not a problem of jsf or priemfaces). the problem is when we use a composit to pass parmetre we should use a type in attribute when is # string like this:

 <ce:attribute name="value" required="true" type="java.util.List"/>

for now i let open this maybe there is other problem :)

Gogo
  • 292
  • 8
  • 19
-1

I advance in the debug I think the question is : it is possible to pass value of datatable in composite attribute ?

<ce:attribute name="value" required="true" />
<p:dataTable value="#{cc.attrs.value}"
Gogo
  • 292
  • 8
  • 19