1

Problem: Trying to display h:inputFile tag based on if a checkbox for a row will display the option to upload a file. The issue arises when I want to uncheck a row (meaning to stop editing the row) and the row is still shown in edit mode.

Before editing a row:

Before clicking on checkbox

While editing a row:

While editing a row

Uncheck the row without saving changes (issue here):

Current issue

Goal: I just want to display the book information as if the user didn't want to change the book information at all (specifically example 1). This problem is still displayed after the user saves the changes using the libraryBean.save() method (specifically example 2).

So in short, I want the result to look like example 1 for when either the user unchecks the row or after the changes are saved.


Code In Question:

<h:inputFile id="file" label="file" style="margin-top: 10px"
    value="#{libraryBean.part}"
    validator="#{libraryBean.validateFile}"
    rendered="#{book.editable}"/>

Additional Info:

XMLNS Libraries:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

LibraryBean is @SessionScoped


Full Code:

<h:form id="frmlibrary" enctype="multipart/form-data">
    <ui:fragment rendered="#{not empty libraryBean.books}">
        <div class="panel panel-default">
            <h:dataTable value="#{libraryBean.books}" class="table table-bordered"
                         var="book" border="1" id="dtLibrary" rendered="#{not empty libraryBean.books}">
                <h:column>
                    <f:facet name="header">Edit</f:facet>
                    <h:selectBooleanCheckbox class="checkbox" value="#{book.editable}" onclick="submit()" />
                </h:column>
                <h:column>
                    <f:facet name="header">Book Cover</f:facet>
                    <image src="ImageServlet?fileID=#{book.libID}"
                           height="150" width="100" />
                    <h:inputFile id="file" label="file" style="margin-top: 10px"
                                 value="#{libraryBean.part}"
                                 validator="#{libraryBean.validateFile}"
                                 rendered="#{book.editable}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Title</f:facet>
                    <h:inputText value="#{book.title}" class="form-control"
                                 rendered="#{book.editable}" size="20"/>
                    <h:outputText value="#{book.title}" 
                                  rendered="#{not book.editable}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Author</f:facet>
                    <h:inputText value="#{book.author}" class="form-control"
                                 rendered="#{book.editable}" size="20"/>
                    <h:outputText value="#{book.author}" 
                                  rendered="#{not book.editable}"/>
                </h:column>
            </h:dataTable>
        </div>
    </ui:fragment>
    <h:commandButton value="Save Library" class="btn btn-info"
                     action="#{libraryBean.save()}" rendered="#{not empty libraryBean.books}"/>
</h:form>

Update:

I have combined my LibraryFileBean with my LibraryBean to implement changing book covers within the libraryBean.save() method. I am still running into the same issue explained above.

The code has been changed throughout this question to reflect this update! Apologies for the inconvenience this may cause

Simple Sandman
  • 900
  • 3
  • 11
  • 34
  • Are the methods `isEditable()` (or `getEditable()`) and `setEditable()` from the `Book` concrete instance being called when you check/uncheck de checkbox? You can try adding a `valueChangeListener` to the checkbox and check if it's being called when checking/unchecking it. – JMSilla Apr 28 '16 at 10:47
  • Have you excluded all of http://stackoverflow.com/q/2118656? – BalusC Apr 29 '16 at 08:01

1 Answers1

0

You'll have to add this to your check box and save button update=":dtLibrary" by doing this the table will be rendered again and within your save method don't forget to set the book.editable property set to false.

raven
  • 2,381
  • 2
  • 20
  • 44