故障排除p:fileUpload PrimeFaces

时间:2015-11-17 04:59:01

标签: jsf file-upload jsf-2 primefaces

我尝试使用PrimeFaces上传文件但是当我运行我的项目时出现问题,compont fileUpload看起来有所不同。您唯一能做的就是选择图像,但禁用上传和取消按钮。

我按照How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null中的所有说明操作,但没有任何作用。

这些是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app 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-app_3_1.xsd"
     version="3.1">

<context-param>
    <param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name>
    <param-value>6Ld7pMESAAAAAHd1VihJkqPUXAJVwU3Cghc8fzrq</param-value>
</context-param>

<context-param>
    <param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
    <param-value>6Ld7pMESAAAAAMhr5WSk5bcRrff8Y08NtDi8Buoq</param-value>
</context-param>

<servlet>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <servlet-name>Faces</servlet-name>
</servlet>

<servlet-mapping>
    <servlet-name>Faces</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>


<session-config>
    <session-timeout>
        60
    </session-timeout>
</session-config>

<filter>
    <filter-name>primeFacesFileUploadFilter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>primeFacesFileUploadFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>

</filter-mapping>


<!--Spring-->

<!--Configuracion para cargar archivos de Spring -->   
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring/app-context.xml
        /WEB-INF/spring/springSecurity.xml
    </param-value>
</context-param>

<!-- Definicion del servlet de Springn-->
<servlet>
    <servlet-name>Spring Servlet</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/app-context.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<!-- Tipo de peticiones que van a ser procesadas por spring-->
<servlet-mapping>
    <servlet-name>Spring Servlet</servlet-name>
    <url-pattern>*.spring</url-pattern>
</servlet-mapping>



<!-- carga el appContext   -->   
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>   

Thes是网页:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<head>
    <title>MonoLibrary - Registro Libro</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>

<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <h2>Registrar libro</h2>
            </div>
        </div>
    </nav>
    <div class="container">
        <div class="col-sm-4">
            <center>
                <div>
                    <img src="img/monote.jpg" width="100%" height="100%"/>
                </div>
            </center>
        </div>
        <div class="col-sm-8">
            <h:form class="form-horizontal">
                <div class="form-group">
                    <label for="titulo" class="col-sm-2 control-label">Título</label>
                    <div class="col-sm-10">
                        <p:inputText value="#{libroController.libro.titulo}" 
                                     type="text" class="form-control" placeholder="Titulo"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="autor" class="col-sm-2 control-label">Autor</label>
                    <div class="col-sm-3">
                        <p:inputText value="#{libroController.libro.nombreAutor}"
                                     type="text" class="form-control" placeholder="NOMBRE"/>
                        <p:inputText value="#{libroController.libro.apellidopAutor}"
                                     type="text" class="form-control" placeholder="APELLIDOP"/>
                        <p:inputText value="#{libroController.libro.apellidomAutor}"
                                     type="text" class="form-control" placeholder="APELLIDOM"/>
                    </div>
                </div>

                <p:fileUpload fileUploadListener="#{libroController.handleFileUpload}" 
                              mode="advanced" disabled="false"
                              dragDropSupport="true"
                              multiple="false" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                              sizeLimit="10000000" style="width:300px" class=""   />                



                <p:commandButton value="Registrar libro"
                                 type="submit" class="btn btn-primary"
                                 ajax="false" action="perfilUsuario.xhtml"
                                 actionListener="#{libroController.guardaLibro(usuarioController.busquedaUsuario(indexController.currentUser).nom_usuario)}"
                                 />
            </h:form>
        </div>
    </div>
</body>
<br/>
<footer>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-footer">
                <center>Hecho en México. Chain Solutions, todos los derechos
                    reservados 2015. Contacto: 
                    <h:outputLink value="mailto:faniarinoa@gmail.com">
                        <f:param name="subject" value="Informes MonoLibrary" />
                        <h:outputText value="mail" />
                    </h:outputLink>
                </center>
            </div>
        </div>
    </nav>
</footer>

This is how it looks p:fileUpload

1 个答案:

答案 0 :(得分:0)

问题与p:fileUpload的风格是因为我没有写 h:身体和h:头部。另一种情况,禁用的Bottons的问题是因为我手动添加了jquery,我删除了tha脚本。现在它正常工作了。非常感谢。