Foi só colocar uniqueFolder=“false” no componente ice:inputFile que ele não grava mais em um subdiretório com o valor da sessão, o engraçado que ele não reconhece essa opção, fica mostrando a mensagem:
Attribute uniqueFolder invalid for tag inputFile according to TLD
mas funciona, será um bug isso?
Bom agora o outro problema é trocar o nome do arquivo, parece fácil mas até agora não consegui…
package ice;
import com.icesoft.faces.component.inputfile.InputFile;
import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
import com.icesoft.faces.webapp.xmlhttp.RenderingException;
import javax.faces.event.ActionEvent;
import java.io.File;
import java.util.EventObject;
public class InputFileBean {
private int percent = -1;
private PersistentFacesState state = null;
private File file = null;
public InputFileBean() {
state = PersistentFacesState.getInstance();
}
public void setPercent(int percent) {
this.percent = percent;
}
public int getPercent() {
return percent;
}
public void setFile(File file) {
this.file = file;
}
public File getFile() {
return file;
}
public void action(ActionEvent event) {
InputFile inputFile = (InputFile) event.getSource();
if (inputFile.getStatus() == InputFile.SAVED) {
fileName = inputFile.getFileInfo().getFileName();
contentType = inputFile.getFileInfo().getContentType();
setFile(inputFile.getFile());
}
if (inputFile.getStatus() == InputFile.INVALID) {
inputFile.getFileInfo().getException().printStackTrace();
}
if (inputFile.getStatus() == InputFile.SIZE_LIMIT_EXCEEDED) {
inputFile.getFileInfo().getException().printStackTrace();
}
if (inputFile.getStatus() == InputFile.UNKNOWN_SIZE) {
inputFile.getFileInfo().getException().printStackTrace();
}
}
public void progress(EventObject event) {
InputFile file = (InputFile) event.getSource();
this.percent = file.getFileInfo().getPercent();
try {
if (state != null) {
state.render();
} else {
System.out.println("state is null");
}
} catch (RenderingException ee) {
System.out.println(ee.getMessage());
}
}
private String fileName = "";
private String contentType = "";
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileName() {
return fileName;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getContentType() {
return contentType;
}
private int status;
public String callAction() {
if (status == InputFile.SAVED) {
return "saved";
}
return "";
}
}
Tentei trocar nessa linha:
fileName = inputFile.getFileInfo().getFileName();
Mas só mostra na tela o nome que eu coloquei, mas o arquivo é gravado no disco com o nome original, alguém sabe como posso mudar o nome do arquivo que esta sendo feito upload?
Obrigado