0

我在其中定义了一个参数web.xmluploadDirectory我试图从其中一个中获取ManagedBean。下面是片段web.xml——

<!-- Primefaces file upload -->
<!-- thresholdSize specifies the maximum file size in bytes to keep uploaded 
    files in memory. If it exceeds this limit, it’ll be temporarily written to 
    disk. -->
<!-- uploadDirectory is the folder where to keep temporary files that exceed 
    thresholdSize. -->
<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    <init-param>
        <param-name>thresholdSize</param-name>
        <param-value>51200</param-value>
    </init-param>
    <init-param>
        <param-name>uploadDirectory</param-name>
        <param-value>/opt/upload/</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

下面是片段ManagedBean——

@ManagedBean
@ViewScoped
public class ProjectInfo implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private static final String destination = FacesContext.getCurrentInstance()
            .getExternalContext().getInitParameter("uploadDirectory");

为什么我越来越nulldestination

4

1 回答 1

1

您定义的参数是过滤器的参数,因此它们在您的托管 bean 中不可用。例如,您可以将此过滤器子类化并添加将此参数置于请求范围内的代码,并从托管 bean 中读取此参数,或者如果您想从托管 bean(其请求未被此过滤器过滤)访问此参数,请定义他们作为<context-param>.

于 2013-04-12T09:23:18.007 回答