I’m using NB 7.2.1 running on glassfifh 3.1 to develop a JSF/Primefaces 3.4 web app. So, when submiting the multipart-form enctype, the event fired by ‘FileUploadListener’ does not allow that another class attribute (like name or age in other JSF inputText) be loaded. Why?
Here is the view:
<h:form enctype="multipart/form-data">
<p:outputLabel value="Nome" for="nome" />
<p:inputText value="#{controller.nome}" id="nome" />
<br />
<p:fileUpload mode="advanced" multiple="true" fileUploadListener="#{controller.doSubmit}" />
</h:form>
Here is the bean:
@ManagedBean
@SessionScoped
public class Controller {
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Controller() {
}
public void doSubmit(FileUploadEvent event) {
System.out.println(getNome());
}
}
In previous ‘getName()’ call, null was returned. Therefore, everything is in the same form. Why I can retrive event.getFile() and dont retrieve getNome() ?
The “upload” button won’t submit the whole form. It will only upload the file.
In order to submit the whole form, you need a normal submit button.
In the file upload listener method, you just have to get hold of the file as a variable in a view scoped bean, so that you can perform the necessary business logic on it in the action method associated with the normal submit button, along with all other input values.
E.g.
with