cancel
Showing results for 
Search instead for 
Did you mean: 

working with beans in beans

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

When i click on a content (image, html, pdf, …), I view these in my own inline reading panel.
Now, I made a new panel where I want to show the details of the content, and also the categorization and versioning of the document.

So, with one click, I'll get almost all the information of the content.

When i click on the content, I call

actionListener="#{CheckinCheckoutBean.inlineFile}"

in this method, i'll set the inline reading on for my new panel.

Now, for the categoryzation and versioning, I need the DocumentDetailsBean.
Is it possible to work with that bean, IN the CheckinCheckoutBean (and in the method Inlinefile?

I used this but I don't know how i can use the methods from the DocumentDetailsBean into the CheckinCheckoutBean.

DocumentDetailsBean docDetails = (DocumentDetailsBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("DocumentDetailsBean");
2 REPLIES 2

sjeek
Champ in-the-making
Champ in-the-making
My problem is allready solved for a big part
but, i'm stuck with this now:


   public String getVersionOverviewHTML() {
      String html = "";
      
      if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE)) {
         VersionHistory history = this.versionService
               .getVersionHistory(getDocument().getNodeRef());

         StringBuilder builder = new StringBuilder(Application.getMessage(
               FacesContext.getCurrentInstance(),
               MSG_HAS_FOLLOWING_CATEGORIES));

         builder.append("<ul>");
         if (history != null) {

            for (Version version : history.getAllVersions()) {
               builder.append("<li>");
               builder.append(version.getVersionLabel() + " ");
               builder.append(version.getDescription() + " ");
               builder.append(version.getCreator() + " ");
               builder.append("</li>");
            }

            builder.append("</ul>");
            html = builder.toString();
         }

      }
      return html;
   }

If you can see in the code, I use the method, to show the versioning of a content. (just for testing)
But, I get a NullpointerException at

VersionHistory history = this.versionService.getVersionHistory(getDocument().getNodeRef());

This code was first in the DocumentDetailsBean, but I moved it to the CheckinCheckoutBean for my inline Reading content.
So, i didn't had to call other Beans in an other Bean.

How can I fix this Exception?

I'll allready import the right classes ect.

when I click in "browse.jsp" on the content. this code is executed



grtz

   public void inlineFile(ActionEvent event) {
      UIActionLink link = (UIActionLink) event.getComponent();
      Map<String, String> params = link.getParameterMap();
      String id = params.get("id");

      if (id != null && id.length() != 0) {
         
         setCurrentNode(id);
         
         Node node = setupContentDocument(id);

         // retrieve the content reader for this node
         ContentReader reader = getContentService().getReader(
               node.getNodeRef(), ContentModel.PROP_CONTENT);
         String mimetype = reader.getMimetype();

         // retrieve string to show image or downloadlink
         String url = (String) node.getProperties().get("url");
         String img = (String) node.getProperties().get("fileType32");
         String name = (String) node.getProperties().get("name");
         String title = (String) node.getProperties().get("title");
         String description = (String) node.getProperties().get(
               "description");

         // looking for the type of file
         if (MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(mimetype)
               || MimetypeMap.MIMETYPE_XML.equals(mimetype)
               || MimetypeMap.MIMETYPE_TEXT_CSS.equals(mimetype)
               || MimetypeMap.MIMETYPE_HTML.equals(mimetype)
               || MimetypeMap.MIMETYPE_XHTML.equals(mimetype)) {
            // make content available
            if (reader != null) {
               // replace(strBericht,vbcrlf,"<br>")
               String text = reader.getContentString();
               text = text.replaceAll("\n", "<br>");
               setInlineContent("<b>" + name + "</b><br><br>" + text);

            } else {
               setInlineContent("");
            }

            // navigate to appropriate screen
            FacesContext fc = FacesContext.getCurrentInstance();
            fc.getApplication().getNavigationHandler().handleNavigation(fc,
                  null, "browse");
         }

         else {
            if (MimetypeMap.MIMETYPE_IMAGE_JPEG.equals(mimetype)
                  || MimetypeMap.MIMETYPE_IMAGE_GIF.equals(mimetype)
                  || MimetypeMap.MIMETYPE_IMAGE_RGB.equals(mimetype)) {
               // make content available
               if (reader != null) {
                  setInlineContent("<b>" + name
                        + "</b><br><br><img src='/alfresco" + url
                        + "'>");

               } else {
                  setInlineContent("");
               }

               // navigate to appropriate screen
               FacesContext fc = FacesContext.getCurrentInstance();
               fc.getApplication().getNavigationHandler()
                     .handleNavigation(fc, null, "browse");
            } else {

               // make content available
               if (reader != null) {
                  setInlineContent("<img src='/alfresco" + img
                        + "'> <A HREF='/alfresco" + url + "'>Download "
                        + name + "</A>");

               } else {
                  setInlineContent("");
               }

               // normal downloadable document
               FacesContext fc = FacesContext.getCurrentInstance();
               fc.getApplication().getNavigationHandler()
                     .handleNavigation(fc, null, "browse");
            }
         }

         setInlineDetail("<img src='/alfresco" + img + "'><br>Name: " + name
               + "<br>Title: " + title + "<br>Description: " + description
               + "<br>Format: " + mimetype + "<br><A HREF='/alfresco"
               + url + "'><b>Download " + name + "</b></A>");
         setInlineCategory(getCategoriesOverviewHTML());
         setInlineVersion(getVersionOverviewHTML());

      }
   }

sjeek
Champ in-the-making
Champ in-the-making
Solved Smiley Happy


public String getVersionOverviewHTML() {

      String html = null;
      UserTransaction tx = null;

      // Start a transaction
      try {
         // Use the Repository helper class to obtain a new transaction
         FacesContext context = FacesContext.getCurrentInstance();
         tx = Repository.getUserTransaction(context, true);
         tx.begin();

         Node node = setupContentDocument(currentNode);

         String name = (String) node.getProperties().get("name");

         VersionService versionService = (VersionService) FacesContextUtils
               .getRequiredWebApplicationContext(context).getBean(
                     "versionService");

         if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE)) {
            VersionHistory history = versionService
                  .getVersionHistory(getDocument().getNodeRef());

            StringBuilder builder = new StringBuilder(Application
                  .getMessage(FacesContext.getCurrentInstance(),
                        MSG_HAS_FOLLOWING_CATEGORIES));

            builder.append("<ul>");
            if (history != null) {

               for (Version version : history.getAllVersions()) {
                  String url = DownloadContentServlet.generateBrowserURL(
                        version.getFrozenStateNodeRef(), name);
                  builder.append("<li>");
                  builder.append("<A HREF='/alfresco" + url
                        + "'>Download v" + version.getVersionLabel()
                        + "</A>" + " ");
                  builder.append(version.getDescription() + " ");
                  builder.append(version.getCreator() + " ");
                  builder.append("</li>");
               }

               builder.append("</ul>");
               html = builder.toString();
            }

         }
         // Commit the transaction
         tx.commit();

      } catch (Exception e) {
         e.printStackTrace();
      }
      return html;
   }