This example builds upon the adding a custom menu item example to give the menu item something to call. A dialog will be defined which will allow the user to select an aspect to add to the space. The extension will then be packaged and deployed. This example is also included as the CustomDialog sample in the SDK.
The new dialog framework allows us to simply define the part of the JSP page that 'does the work'. In this example we'll create a simple label and a drop down list of aspects for the the user to choose from.
The JSP code to do this (1.4 onwards) is as follows:
The first 4 lines simply include the JSF and Alfresco tag libraries. The next line outputs some text, in this example the string to display is coming from webclient.properties (to add custom strings see Adding Custom I18N Strings). The remaining rows produce the list of aspects to display. The list is taken from the configuration for the Action Wizards, thus we reference the RunActionWizard bean. The last thing to mention is 'DialogManager.bean'. This expression refers to bean being used by the current dialog. As an explicit bean is not referenced this page could be re-used in multiple dialogs.
Copy the code above into your favorite editor and save the file as 'add-aspect.jsp'.
Defining the dialog
The next step is to define the dialog that will be launched when the menu item is selected. Add the following XML within the config element in your web-client-config-custom.xml:
<dialogs> <dialog name='addAspect' page='/jsp/extension/add-aspect.jsp' managed-bean='AddAspectDialog' icon='/images/icons/add_content_large.gif' title='Add Aspect' description='Adds an aspect to the selected node' /> </dialogs>
The name attribute defines the id of the dialog used to launch it via the action defined above.
The managed-bean attribute is the name of the backing bean used by the dialog, we will define this in the next step.
The page attribute points to the custom JSP we created in the previous section.
The other attributes are self-explanatory.
Creating and registering the backing bean implementation
The final task is to create and implement the backing bean and registering it with MyFaces.
Create a class called 'AddAspectDialog' in the 'org.alfresco.sample' package and extend it from org.alfresco.web.bean.dialog.BaseDialogBean. For full details on creating dialog beans refer to the Dialog And Wizard Framework Guide.
For our example all we need to do is add the chosen aspect to the current space, this is accomplished in the finishImpl() method. The code we'll need is shown below.