1

I am trying to update a row in a JSF data table based on the method in this article: http://www.mkyong.com/jsf2/how-to-update-row-in-jsf-datatable/

When I click Save, I am getting this error message:

Conversion Error setting value '1970-09-08' for 'null Converter'.

Screenshot: Screenshot

Markup:

<h:form>
                        <h:commandButton action="addEmployee" value="Add New" class="btn btn-primary" />
                        <br />

                        <h:dataTable class="table table-striped" value="#{employeeCollection.items}" var="item">
                            <h:column>
                                <f:facet name="header">Edit</f:facet>
                                <h:commandButton action="#{employeeCollection.edit(item)}" value="Edit" class="btn" rendered="#{not item.isEditing}" />
                                <h:commandButton action="#{employeeCollection.save(item)}" value="Save" class="btn btn-success" rendered="#{item.isEditing}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">First Name</f:facet>
                                <h:inputText value="#{item.firstName}" rendered="#{item.isEditing}" />
                                <h:outputText value="#{item.firstName}" rendered="#{not item.isEditing}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">Last Name</f:facet>
                                <h:inputText value="#{item.lastName}" rendered="#{item.isEditing}" />
                                <h:outputText value="#{item.lastName}" rendered="#{not item.isEditing}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">Date of Birth</f:facet>
                                <h:inputText value="#{item.dateOfBirth}" rendered="#{item.isEditing}" />
                                <h:outputText value="#{item.dateOfBirth}" rendered="#{not item.isEditing}" />
                            </h:column>
                        </h:dataTable>
                    </h:form>

I would post the managed bean code, but I don't think that's necessary because when clicking the Save button, the save(item) function never seems to be called anyway... so it must be something else. I am new to Java, so probably I'm forgetting something very basic here, somewhere...

Matt
  • 6,787
  • 11
  • 65
  • 112

1 Answers1

4

The error describes that there was an error converting the String using a null converter. This happens if you use a Date object in your <h:inputText> tag component without a DateTime converter. You can fix this by changing the JSF code:

<h:column>
    <f:facet name="header">Date of Birth</f:facet>
    <h:inputText value="#{item.dateOfBirth}" rendered="#{item.isEditing}">
        <!-- adding the datetime converter -->
        <f:convertDateTime pattern="yyyy-MM-dd" />
    </h:inputText>
    <h:outputText value="#{item.dateOfBirth}" rendered="#{not item.isEditing}" />
</h:column>

Still, it's not a good approach to handle the date validations for you and your user. It would be better to use a third party library that provides you a Calendar component like PrimeFaces Calendar or RichFaces Calendar.

Note that you can use the JSF provided converters for DateTime and Numbers, and you can create your custom data converters. More info:

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332