The application need to import excel files (.xlsx) to populate one database table. The problem comes when I try to upload the file through AJAX. The validator is never called (and the listener never too). When I try to upload the file, a error is thrown from JSF AJAX JavaScript file and show in the browser's console: TypeError: partialResponse is not defined
.
My first thought was this is a bug, but i'm not sure. It's my first JSF project.
<h:form id="travels-form" class="toolbar ui form" enctype="multipart/form-data">
<div class="five wide field">
<input type="text" id="search" placeholder="Buscar..." />
</div>
<div class="actions">
<div class="inline field wide">
<h:selectOneMenu valueChangeListener="#{travelBean.filter}" >
<f:selectItem itemValue="" itemLabel="Todas las placas" />
<f:selectItems value="#{travelBean.licensePlates}" var="plate"
itemValue="${plate}" itemLabel="${plate}" />
<f:ajax execute="@this" render=":tblTravels" />
</h:selectOneMenu>
</div>
<h:outputLabel for="excel" value="Excel" styleClass="ui positive button" />
<h:inputFile id="excel" value="#{excelImporterBean.workbook}"
validator="#{excelImporterBean.validate}"
style="display: none">
<f:ajax execute="@this" render="excelMessage :tblTravels"
listener="#{excelImporterBean.onLoadWorkbook}"/>
</h:inputFile>
<h:message id="excelMessage" for="excel" errorClass="error-message"/>
<h:outputLink value="#{request.contextPath}/home/recorridos/nuevo"
styleClass="ui primary button">
Registrar
</h:outputLink>
</div>
</h:form>
This are the ExcelImporterBean methods (validator and listener):
public void onLoadWorkbook(AjaxBehaviourEvent ev) {
excelImporter.importWorkbook(workbook);
}
public void validate(FacesContext ctx, UIComponent comp, Object value) {
FacesMessage message = null;
Part _workbook = (Part) value;
if(((Part) value).getContentType().equals(EXCEL_TYPE)) {
message = new FacesMessage("Solo archivos excel 2007+ (.xlsx)");
}
if(message != null) {
throw new ValidatorException(message);
}
}
The app is running on:
- Tomcat 8.0.35
- JSF (mojarra) 2.2.13
Edit
- On Firefox the error is: partialResponse is not defined
- On Chrome is: cannot read property getAttribute of undefined