I am evaluating cuba platform / studio . Very good so far… but I came to this error following an example on documentation, Version 6.8
This is the controller code;
package com.company.t1.web.cliente;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.t1.entity.Cliente;
import com.haulmont.cuba.core.entity.FileDescriptor;
import com.haulmont.cuba.core.global.FileStorageException;
import com.haulmont.cuba.gui.components.FileUploadField;
import com.haulmont.cuba.gui.data.DataSupplier;
import com.haulmont.cuba.gui.upload.FileUploadingAPI;
import javax.inject.Inject;
import java.util.Map;
public class ClienteEdit extends AbstractEditor<Cliente> {
@Inject
private FileUploadField ulfimagen;
@Inject
private FileUploadingAPI fileUploadingAPI;
@Inject
private DataSupplier dataSupplier;
@Override
public void init(Map<String, Object> params) {
ulfimagen.addFileUploadSucceedListener(event -> {
FileDescriptor fd = ulfimagen.getFileDescriptor();
try {
// save file to FileStorage
// FileDescriptor userImageFile = Cliente.getImagen();
// imgimagen.setSource(FileDescriptorResource.class).setFileDescriptor(userImageFile);
fileUploadingAPI.putFileIntoStorage(ulfimagen.getFileId(), fd);
} catch (FileStorageException e) {
throw new RuntimeException("Error saving file to FileStorage", e);
}
// save file descriptor to database
dataSupplier.commit(fd);
showNotification("Uploaded file: " + ulfimagen.getFileName(), NotificationType.HUMANIZED);
});
ulfimagen.addFileUploadErrorListener(event ->
showNotification("File upload error", NotificationType.HUMANIZED));
}
}
This is the layout
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://editorCaption"
class="com.company.t1.web.cliente.ClienteEdit"
datasource="clienteDs"
focusComponent="tfPrimerNombre"
messagesPack="com.company.t1.web.cliente">
<dsContext>
<datasource id="clienteDs"
class="com.company.t1.entity.Cliente"
view="cliente-view_1"/>
</dsContext>
<dialogMode height="600"
width="800"/>
<layout expand="windowActions"
spacing="true">
<grid caption="Datos del Cliente"
responsive="true"
spacing="true"
width="800px">
<columns count="4"/>
<rows>
<row>
<label id="lbPrimerNombre"
align="MIDDLE_LEFT"
height="20px"
value="Primer Nombre"/>
<textField id="tfPrimerNombre"
align="MIDDLE_LEFT"
datasource="clienteDs"
property="primerNombre"
width="150px"/>
<label id="lbSegundoNombre"
align="MIDDLE_LEFT"
responsive="true"
value="Segundo Nombre"/>
<textField id="tfSegundoNombre"
datasource="clienteDs"
property="segundoNombre"/>
</row>
<row>
<label align="MIDDLE_LEFT"
value="Primer Apellido"/>
<textField id="tfPrimer Apellido"
datasource="clienteDs"
height="32px"
property="primerApellido"
width="150px"/>
<label id="lbSegundoApellido"
align="MIDDLE_LEFT"
height="17px"
responsive="true"
value="Segundo Apellido"/>
<textField id="tfSegundoApellido"
datasource="clienteDs"
property="segundoApellido"/>
</row>
<row>
<dateField id="dfFechaNacimiento"
caption="Fecha de Nacimiento"
datasource="clienteDs"
height="31px"
property="fechaNacimiento"/>
<lookupField id="lfPaisNacimiento"
caption="Pais de Nacimiento"
datasource="clienteDs"
optionsEnum="com.company.t1.entity.Pais"
property="paisNacimiento"/>
<textField id="tfNacionalidad"
caption="Nacionalidad"
datasource="clienteDs"
height="30px"
property="nacionalidad"/>
<lookupField id="lfgenero"
caption="Genero"
datasource="clienteDs"
optionsEnum="com.company.t1.entity.Genero"
property="genero"
required="true"
responsive="true"/>
</row>
<row>
<lookupField id="lfTipoIdentificacion"
caption="Tipo de Identificacion"
colspan="3"
datasource="clienteDs"
height="34px"
optionsEnum="com.company.t1.entity.TipoIdentificacion"
property="tipoIdent"/>
<textField id="tfIdentificacion"
caption="Numero de Identificacion"
datasource="clienteDs"
height="31px"
property="identificacacion"/>
</row>
<row>
<upload id="ulfimagen"
datasource="clienteDs"
fileStoragePutMode="IMMEDIATE"
property="imagen"/>
</row>
<row/>
</rows>
</grid>
<hbox height="44px"
margin="true"
responsive="true"
spacing="true"/>
<frame id="windowActions"
screen="editWindowActions"/>
</layout>
</window>