Jsf primefaces中向导内的文件上载-上载的文件未显示?

Jsf primefaces中向导内的文件上载-上载的文件未显示?,jsf,netbeans,primefaces,nested-forms,Jsf,Netbeans,Primefaces,Nested Forms,我使用Primefaces手册示例作为向导,并用简单的文件上载表单替换其中一个选项卡。我有所有必要的库和web inf中的过滤器,以便文件上传工作。使用Netbeans运行项目不会显示任何错误(向导会显示,UI会响应),但文件不会上载,并且我的fileBean类不会显示任何系统消息。知道我哪里出错了吗?index.html中的嵌套表单是否有问题?谢谢 index.xhtml: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE h

我使用Primefaces手册示例作为向导,并用简单的文件上载表单替换其中一个选项卡。我有所有必要的库和web inf中的过滤器,以便文件上传工作。使用Netbeans运行项目不会显示任何错误(向导会显示,UI会响应),但文件不会上载,并且我的fileBean类不会显示任何系统消息。知道我哪里出错了吗?index.html中的嵌套表单是否有问题?谢谢

index.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>The rings of scholarship</title>
    </h:head>
    <h:body>
        <h:form>

            <p:growl id="growl" sticky="true" showDetail="true"/>

            <p:wizard widgetVar="wiz"
                      flowListener="#{userWizard.onFlowProcess}">

                <p:tab id="personal" title="Personal">

                    <p:panel header="Personal Details">

                        <h:messages errorClass="error"/>

                        <h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
                            <h:outputText value="Firstname: *" />
                            <p:inputText required="true" label="Firstname"
                                         value="#{userWizard.user.firstname}" />

                            <h:outputText value="Lastname: *" />
                            <p:inputText required="true" label="Lastname"
                                         value="#{userWizard.user.lastname}" />

                            <h:outputText value="Age: " />
                            <p:inputText value="#{userWizard.user.age}" />

                            <h:outputText value="Skip to last: " />
                            <h:selectBooleanCheckbox value="#{userWizard.skip}" />
                        </h:panelGrid>
                    </p:panel>
                </p:tab>

                <p:tab id="upload" title="File upload">
                    <p:panel header="File upload">

                        <h:messages errorClass="error"/>

                        <h:panelGrid columns="2" columnClasses="label, value">
                            <h:form enctype="multipart/form-data">
                                <p:fileUpload value="#{fileBean.file}" mode="simple" />
                                <p:commandButton value="Submit" action="#{fileBean.save}" ajax="false"/>
                            </h:form>
                        </h:panelGrid>
                        <h:outputText value="Skip to last: " />
                        <h:selectBooleanCheckbox value="#{userWizard.skip}" />
                    </p:panel>
                </p:tab>

                <p:tab id="contact" title="Contact">
                    <p:panel header="Contact Information">

                        <h:messages errorClass="error"/>

                        <h:panelGrid columns="2" columnClasses="label, value">
                            <h:outputText value="Email: *" />
                            <p:inputText required="true" label="Email"
                                         value="#{userWizard.user.email}" />

                            <h:outputText value="Phone: " />
                            <p:inputText value="#{userWizard.user.phone}"/>

                            <h:outputText value="Additional Info: " />
                            <p:inputText value="#{userWizard.user.info}"/>
                        </h:panelGrid>
                    </p:panel>
                </p:tab>

                <p:tab id="confirm" title="Confirmation">
                    <p:panel header="Confirmation">

                        <h:panelGrid id="confirmation" columns="6">
                            <h:outputText value="Firstname: " />
                            <h:outputText styleClass="outputLabel"
                                          value="#{userWizard.user.firstname}" />

                            <h:outputText value="Lastname: " />
                            <h:outputText  styleClass="outputLabel"
                                           value="#{userWizard.user.lastname}"/>

                            <h:outputText value="Age: " />
                            <h:outputText styleClass="outputLabel"
                                          value="#{userWizard.user.age}" />>

                            <h:outputText value="Email: " />
                            <h:outputText styleClass="outputLabel"
                                          value="#{userWizard.user.email}" />

                            <h:outputText value="Phone " />
                            <h:outputText styleClass="outputLabel"
                                          value="#{userWizard.user.phone}"/>

                            <h:outputText value="Info: " />
                            <h:outputText styleClass="outputLabel"
                                          value="#{userWizard.user.info}" />

                            <h:outputText />
                            <h:outputText />
                        </h:panelGrid>

                        <p:commandButton value="Submit" update="growl" 
                                         actionListener="#{userWizard.save}"/>

                    </p:panel>
                </p:tab>

            </p:wizard>

        </h:form>

    </h:body>
</html>

从消除嵌套表单开始。。。一个在向导周围,一个在


尝试从选项卡中删除内部表单,并用

thx@Daniel包装向导,但我认为标签(及其“多部分/表单数据”)是文件上载所必需的?如何摆脱嵌套表单并在向导中获得文件上载?在每个选项卡中放置简单的
(除了上载的选项卡),并在上载的选项卡中放置
。。我尝试过,但后来收到一条错误消息,说向导primefaces标记本身应包含在表单中。。。(这将再次创建嵌套表单情况)。有进一步的想法吗@Danielso请尝试从选项卡中删除内部表单,并使用
包装向导。您使用的primefaces版本是什么?
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import org.apache.commons.io.IOUtils;
import org.primefaces.model.UploadedFile;

@ManagedBean
@ViewScoped
public class FileBean implements Serializable{

    private UploadedFile file;
/**
 * Creates a new instance of FileBean
 */
public FileBean() {
}

public UploadedFile getFile() {
    System.out.println("we get file");
    return file;
}

public void setFile(UploadedFile file) throws FileNotFoundException, IOException {
    System.out.println("we set file");
    this.file = file;

}

public void save() throws IOException {
    System.out.println("we save file");
    IOUtils.copy(file.getInputstream(), new FileOutputStream("D:\\" + file.getFileName()));
    BufferedReader br = new BufferedReader(new InputStreamReader(file.getInputstream()));
    String currLine = br.readLine();
    Integer counterLines = 0;
    while (currLine != null && counterLines < 5) {
        System.out.println("currLine is: " + currLine);
        counterLines++;
    }

}
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.event.FlowEvent;

@ManagedBean
@ViewScoped
public class UserWizard implements Serializable{

    private User user = new User();
    private boolean skip;
    private static final Logger logger = Logger.getLogger(UserWizard.class.getName());

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void save(ActionEvent actionEvent) {
        //Persist user

        FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public boolean isSkip() {
        return skip;
    }

    public void setSkip(boolean skip) {
        this.skip = skip;
    }

    public String onFlowProcess(FlowEvent event) {
        logger.log(Level.INFO, "Current wizard step:{0}", event.getOldStep());
        logger.log(Level.INFO, "Next step:{0}", event.getNewStep());

        if (skip) {
            skip = false;   //reset in case user goes back
            return "confirm";
        } else {
            return event.getNewStep();
        }
    }
}