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:
While editing a row:
Uncheck the row without saving changes (issue here):
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