0

I have defined a parameter inside web.xml as uploadDirectory, which I am trying to get from one of ManagedBean. Below is the snippet of 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>

Below is the snippet of ManagedBean-

@ManagedBean
@ViewScoped
public class ProjectInfo implements Serializable {

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

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

Why I am getting null as destination?

ravi
  • 6,140
  • 18
  • 77
  • 154

1 Answers1

1

Parameters you defined are parameters of filter, so they are not available in your managed bean. You can, for example, subclass this Filter and add code which put this parameter in request scope, and read this parameter from managed bean, or if you want to access this parameter from managed beans, whose requests are not filtered by this filter, define them as <context-param>.

partlov
  • 13,789
  • 6
  • 63
  • 82
  • My objective is just to define an `uploadDirectory` outside from the `managedbean`, so that i can change it whenever require. Can you please explain your suggestion with updated `web.xml` if required? – ravi Apr 12 '13 at 09:27
  • 1
    Yes, that is what I think. – partlov Apr 12 '13 at 09:30