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.
As mentioned in the introduction we will use the adding a custom menu item example as a starting point.
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 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'.
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.
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.
Copy the code above into your favorite editor and save the file.
Finally, we need to register the dialog class with MyFaces as a managed bean.
Copy the XML above into your favorite editor and save the file as 'faces-config.xml'.
We now have all the individual pieces, we just need to package and deploy the sample, see the Packaging And Deploying Extensions guide to see how.
Alternatively, you can download the SDK from sourceforge or get the latest code from SVN where you'll find a prepared CustomDialog sample.
Note The recommended approach is to package up extensions as AMP files. Here is the SDK sample repackaged as an AMP file (BROKEN LINK).