RSF Debugging Exercise
Introduction
This exercise starts with a CRUD tool generated using Sakai App Builder plugin for eclipse. The tool source has been modified to introduce a range of common errors that an RSF developer may encounter.
Getting Started
- Download the source code for the exercise into an existing sakai source directory.
- Import the source code for the exercise into Eclipse.
- Go to command line, run "maven bld dpl" from source directory (keep the command line window open)
- Stop Sakai, start Sakai, watch console output
- Wait for "Server startup", and then attempt to load site.
Your portal should fail to load, there will be errors in the console output from tomcat. If you wish to work through the exercise yourself, stop reading now and work on your own. The remainder of the document is an answer key that describes the errors that appear and details how to fix them.
Answer Key
- Error 1
- In short, the error that appears is cryptic, but is common when including your own version of the Spring jars with your tool.
- Edit tool/project.xml and comment out or remove the lines that bundle the spring jars in the tool war file.
- Stop sakai, run "maven sakai", start Sakai
- The startup of Sakai and our tool should proceed normally and the portal should be available again.
- Add the Tool to a Site
- Log in as an admin
- Create a test site that includes our tool.
- Open tool. An error appears in both the web interface and the console.
- Error 2
- The console output indicates that this is an RSF error. Looking at the available templates, we can see that the template filename is different from the View ID specified in the producer.
- Open tool/src/java/ItemsProducer.java and tool/src/webapp/templates
- Update the view ID to match the name of the template file.
- Stop sakai, run "maven sakai", start Sakai
- Log in, open test site, open tool.
- A Spring error should appear in the console output.
- Error 3
- Looking at the console output, we can see that somewhere "locale" is incorrectly specified as "localle".
- Open tool/src/java/ItemsProducer.java, look for the SetLocale method which exists and appears to be appropriate.
- Open tools/src/webapp/WEB-INF/applicationContext.xml. The locale does not appear to be injected in the application context, so we should look at the request context instead.
- Open tool/src/webapp/WEB-INF/requestcontext.xml. Looking at the file, we can see that the property that should tell Spring to inject the locale into the producer has a typo. Fix the typo.
- Stop sakai, run "maven sakai", start Sakai
- Log in, open test site, open tool
- The tool loads without any further stack traces.
- Error 4
- Try "Add Item". An error appears.
- Looking at the console output, this appears to be an RSF template error, the error includes a filename and line number.
- open the file specified (tool/src/webapp/templates/AddItem.html) and add a closing div before the </body> tag.
- Stop sakai, run "maven sakai", start Sakai
- Log in, open test site, open tool
- Add two items, one hidden, one not hidden. The add function works.
- Error 5
- Looking at the items view, note that the hidden column is not displayed.
- Open Items.html. Note the area of the template that should display the hidden field and make a note of the rsf:id value used.
- Open ItemsProducer.java. Note that the section of code that should fill in the hidden field uses an RSF ID that doesn't match the template.
- Make it match.
- Stop sakai, run "maven sakai", start Sakai
- Log in, open test site, open tool
- The hidden field now displays correctly
- Error 6
- Note that the timestamp is not filled in (it says "DATE")
- Open ItemsProducer.java. Show the section that fills in the id.
- Open Items.html. Show them the definition for the date stamp (rsf:id attribute is wrong).
- Fix it, restart, reopen tool
- The timestamp is now displayed correctly.
- Error 7
- Attempt to change the hidden field for an existing item without changing the title.
- Note that the update message contains the text "null" where the title of the updated field should appear.
- Quick Tip: Find the file that handles the updates by searching for "Updated item". In this case, it's an action handling method in the backing bean.
- Open the backing bean. Note that the displayed message uses newItem (which only reflects the information that has been passed). Change newItem.getTitle() to updateItem.getTitle() like so:
String message = "Updated item: " + updateItem.getTitle();
- Rebuild, restart, reopen tool.
- Edit an existing item and change the value of the hidden field without updating the title. The title is now displayed correctly.