cancel
Showing results for 
Search instead for 
Did you mean: 

FacesContext.getCurrentInstance()

sjeek
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to upload files with just one button (so, the "upload" and the "finish" button together.)

Now, I made a copy of UploadFileServlet and worked with the copy.

This code works fine

// —————————————-
         StringBuilder builder = new StringBuilder();

         builder.append(Repository.getMimeTypeForFileName(FacesContext
               .getCurrentInstance(), bean.getFileName()));
         String mime = builder.toString();

         // set mimetype of content
         addwiz.setContentType(mime);

         // set inline Edit if mimetype = HTML
         addwiz.setInlineEdit(addwiz.getContentType().equals(
               MimetypeMap.MIMETYPE_HTML));

         // Try and extract metadata from the file
         ContentReader cr = new FileContentReader(this.file);
         cr.setMimetype(addwiz.getContentType());

         // create properties for content type
         Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(
               5, 1.0f);

         // if (Repository.extractMetadata(FacesContext.getCurrentInstance(),
         // cr, contentProps))
         // {
         addwiz.setAuthor((String) (contentProps
               .get(ContentModel.PROP_AUTHOR)));
         addwiz
               .setTitle((String) (contentProps
                     .get(ContentModel.PROP_TITLE)));
         addwiz.setDescription((String) (contentProps
               .get(ContentModel.PROP_DESCRIPTION)));
         // }

          if (addwiz.getTitle() == null)
          {
             addwiz.setTitle(bean.getFileName());
          }

But, now, I want to upload the files affcourse:


addwiz.quick(this.file, null);


public String quick(File fileContent, String strContent)
   {     
      String outcome = quicksaveContent(fileContent, strContent);
     
      // now we know the new details are in the repository, reset the
      // client side node representation so the new details are retrieved
      if (this.editMode)
      {
         this.browseBean.getDocument().reset();
      }
     
      return outcome;
   }

Now, in the saveContent, I always get a nullpointer at the FacesContext.getCurrentInstance()!
At the first, I get this exception also at the first code, but I made muy way around it.

someone told me that this problem could be that the FacesContext.getCurrentInstance() use a HTTP request and the Servlet not, so that's why I get the nullpointer, but here stops my knowlidge of java  Smiley Happy

If you also can see in the first code i did
// if (Repository.extractMetadata(FacesContext.getCurrentInstance(),

so i would not have a nullpointer offcourse

so, if someone could help me?

thx
2 REPLIES 2

sjeek
Champ in-the-making
Champ in-the-making
Or is it possible to use the method
AddContentWizard.Finish
in the UploadFileServlet ???

kevinr
Star Contributor
Star Contributor
Servlets are outside of the JavaServerFaces (JSF) lifecycle, so do not normally have access to the FacesContext object which is specific to the JSF framework. We mostly have equivilent methods on Application or Repository object that take the ServletContext object instead.

Thanks,

Kevin
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.