AnsweredAssumed Answered

FacesContext.getCurrentInstance()

Question asked by sjeek on Apr 12, 2006
Latest reply on Apr 13, 2006 by kevinr
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  :)

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

Outcomes