cancel
Showing results for 
Search instead for 
Did you mean: 

[solved] problem with BrowseBean in a custom Dialog

ethan
Champ in-the-making
Champ in-the-making
Hello Smiley Happy

I read the wiki page about Adding a Custom Dialog and I tried to use it to create my own custom Dialog to add tags to a Document node.

I followed the instructions but when I test the Dialog, there's a NullPointerException in my AddTagsDialog.java class. The BrowseBean.getDocument() is null. Therefore, I can't get the noderef of the current document and set its tags property.

There is my code for the entire custom dialog:

in web-client-config-custom.xml (There I used BrowseBean.setupContentAction instead of BrowseBean.setupSpaceAction used in the wiki page)

<action id="add_tags">
   <permissions>
      <permission allow="true">Contributor</permission>
   </permissions>
   <label-id>add-tags</label-id>
   <image>/custom/images/icons/pencil.png</image>
   <action>dialog:addTags</action>
   <action-listener>#{BrowseBean.setupContentAction}</action-listener>
   <params>
            <param name="ref">#{actionContext.id}</param>
         </params>
</action>

My jsp page :


<table cellpadding="2" cellspacing="2" border="0" width="100%">
   <tr>
      <td colspan="2" class="mainSubTitle"><h:outputText value="Enter some Tags" /></td>
   </tr>
   <tr>
      <td colspan="2" class="paddingRow"></td>
   </tr>
   <tr>
      <td>
         <h:outputText value="Tags :"/>
      </td>
      <td width="95%">
         <h:inputText id="tags" value="" size="50" maxlength="1024" />
      </td>
   </tr>
   <tr><td class="paddingRow"></td></tr>
</table>

My AddTagsDialog class : (this.browseBean.getDocument() return null and so do the getNodeRef()…)


protected String finishImpl(FacesContext context, String outcome) throws Throwable {
      
       // get the space the action will apply to
       NodeRef nodeRef = this.browseBean.getDocument().getNodeRef();
        
       // add the aspect if it is not already present on the node
        QName tagAspect = QName.createQName("extension.tags", "taggable");
        if (getNodeService().hasAspect(nodeRef, tagAspect) == false)
        {
           getNodeService().addAspect(nodeRef, tagAspect, null);
        }
       
        // create the tags as a list
        List<String> tagsList = new ArrayList<String>();
        if (this.tags != null && this.tags.length() > 0)
        {
           StringTokenizer tokenizer = new StringTokenizer(this.tags, ",");
           while (tokenizer.hasMoreTokens())
           {
              tagsList.add(tokenizer.nextToken().trim());
           }
        }
       
        // set the tags property
        QName tagsProp = QName.createQName("extension.tags", "tags");
        getNodeService().setProperty(nodeRef, tagsProp, (Serializable)tagsList);
        
       // return the default outcome
       return outcome;

   }
   
   public boolean getFinishButtonDisabled(){      
       return false;
   }

   public void setTags(String tags){
       this.tags = tags;
   }
   
    public String getTags(){
        return tags;
    }

And my faces-config-custom.xml file :


<managed-bean>
      <managed-bean-name>AddTagsDialog</managed-bean-name>
      <managed-bean-class>my.custom.web.ui.dialogs.AddTagsDialog</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>browseBean</property-name>
         <value>#{BrowseBean}</value>
      </managed-property>
</managed-bean>

Did I missed something?
2 REPLIES 2

ethan
Champ in-the-making
Champ in-the-making
Ok I found my mistake. In the web-client-config-custom.xml file, the id of the parameter actionContext.id was set to "ref" and the BrowseBean.setupContentAction() method was waiting a parameter with the id "id".

Now that this works, I have another problem. in the AddTagsDialog class, the attribute tags is null. The class doesn't get the value from the inputText in the simpletags.jsp page Smiley Surprised

In the wiki tutorial, the inputText component in the JSP doesn't have any id or name. So how does the AddAspectDialog class know the value of this component?

ethan
Champ in-the-making
Champ in-the-making
Ok, here is the solution. I just needed to write the inputText component as :

<h:inputText value="#{DialogManager.bean.tags}" />

I was reading the wiki page about DialogManager and I found out that bean was referring to my AddTagsDialog class and that I just needed to add tags to refer to the tags attribute of this class Smiley Happy