我是java&的新手jsf框架。我有一个情况,让我真的很困惑。我正在尝试在jsf中创建上传表单,支持bean是请求作用域,用户必须登录才能使用此表单。当我测试提交表单时,验证消息没有出现,表单只是刷新而没有任何验证/必需的消息。我尝试在谷歌或stackoverflow中找到答案,但它不起作用。但是,当我尝试创建简单的应用程序时,我可以上传我的文件,如下面的表格,没有登录功能。
我的表单如下所示:
<h:form id="frMember" enctype="multipart/form-data">
<h:inputText id="username" value="#{memberForm.email}" required="true" requiredMessage="username_required_message" pt:placeholder="username"/><br/><br/>
<h:inputFile value="#{memberForm.fileFoto}" required="true" requiredMessage="file_required_message"/><br/>
<h:commandButton value="upload" action="#{memberForm.upload()}" class="btn btn-danger"/>
</h:form>
我正在使用glassfish 4,JSF 2.2.7,Netbeans 8,而且我没有像tomahawk fileupload那样使用第三方。我也尝试使用谷歌搜索和搜索stackoverflow来解决我的问题,但我仍然无法解决它。
更新
这是我的控制器
public class MemberFormView implements Serializable {
private Part fileFoto;
/**
* Creates a new instance of MemberFormView
*/
public MemberFormView() {
}
public void upload() throws IOException {
String fileName = FilenameUtils.getName(fileFoto.getName());
String contentType = fileFoto.getContentType();
try (InputStream input = fileFoto.getInputStream()) {
Files.copy(input, new File("/var/AppFile/tmp/", fileFoto.getName()).toPath());
}
}
}
这是我的faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<managed-bean>
<managed-bean-name>memberForm</managed-bean-name>
<managed-bean-class>controller.member.MemberFormView</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>