Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java =================================================================== diff -u -rdeeaba2ec6d90361b2d8a53dc36ef14793e08caa -r3f27eea9deb1424106b5397c4559d3f609416399 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java (.../NbAuthoringAction.java) (revision deeaba2ec6d90361b2d8a53dc36ef14793e08caa) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringAction.java (.../NbAuthoringAction.java) (revision 3f27eea9deb1424106b5397c4559d3f609416399) @@ -39,9 +39,9 @@ import org.lamsfoundation.lams.tool.noticeboard.service.NoticeboardServiceProxy; import org.lamsfoundation.lams.tool.noticeboard.util.NbAuthoringUtil; +import org.lamsfoundation.lams.util.WebUtil; - /** * Creation Date: 20-05-05 * Modified Date: 03-06-05 @@ -78,8 +78,8 @@ */ public ActionForward basic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - copyRichTextOnlineInstrnValue(request, (NbAuthoringForm)form); - copyRichTextOfflineInstrnValue(request, (NbAuthoringForm)form); + NbAuthoringForm nbForm = (NbAuthoringForm)form; + copyInstructionFormProperty(request, nbForm); return mapping.findForward(NoticeboardConstants.BASIC_PAGE); } @@ -96,8 +96,8 @@ */ public ActionForward instructions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - copyRichTextContentValue(request, (NbAuthoringForm)form); - + NbAuthoringForm nbForm = (NbAuthoringForm)form; + copyInstructionFormProperty(request, nbForm); return mapping.findForward(NoticeboardConstants.INSTRUCTIONS_PAGE); } @@ -106,8 +106,8 @@ */ public ActionForward done(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - copyRichTextOnlineInstrnValue(request, (NbAuthoringForm)form); - copyRichTextOfflineInstrnValue(request, (NbAuthoringForm)form); + NbAuthoringForm nbForm = (NbAuthoringForm)form; + copyInstructionFormProperty(request, nbForm); return mapping.findForward(NoticeboardConstants.BASIC_PAGE); } @@ -124,13 +124,11 @@ public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws NbApplicationException { NbAuthoringForm nbForm = (NbAuthoringForm)form; + copyInstructionFormProperty(request, nbForm); + INoticeboardService nbService = NoticeboardServiceProxy.getNbService(getServlet().getServletContext()); - Long content_id = (Long)request.getSession().getAttribute(NoticeboardConstants.TOOL_CONTENT_ID); + Long content_id = NbAuthoringUtil.convertToLong(nbForm.getToolContentId()); - copyRichTextContentValue(request, nbForm); - copyRichTextOnlineInstrnValue(request, nbForm); - copyRichTextOfflineInstrnValue(request, nbForm); - //throws exception if the content id does not exist checkContentId(content_id); @@ -141,58 +139,9 @@ return mapping.findForward(NoticeboardConstants.BASIC_PAGE); } - /** - * The form bean property content is set - * with the value of richTextContent - * @param request - * @param form - */ - private void copyRichTextContentValue(HttpServletRequest request, NbAuthoringForm form) - { - String content = (String)request.getParameter(NoticeboardConstants.RICH_TEXT_CONTENT); - if(content != null) - { - form.setContent(content); - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_CONTENT, content); - - } - } - /** - * The form bean property onlineInstructions is set - * with the value of richTextOnlineInstructions - * @param request - * @param form - */ - private void copyRichTextOnlineInstrnValue(HttpServletRequest request, NbAuthoringForm form) - { - String onlineInstruction = (String)request.getParameter(NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN); - if(onlineInstruction != null) - { - form.setOnlineInstructions(onlineInstruction); - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN, onlineInstruction); - - } - } /** - * The form bean property offlineInstructions is set - * with the value of richTextOfflineInstructions - * @param request - * @param form - */ - private void copyRichTextOfflineInstrnValue(HttpServletRequest request, NbAuthoringForm form) - { - String offlineInstruction = (String)request.getParameter(NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN); - if(offlineInstruction != null) - { - form.setOfflineInstructions(offlineInstruction); - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN, offlineInstruction); - - } - } - - /** * It is assumed that the contentId is passed as a http parameter * if the contentId is null, an exception is thrown, otherwise proceed as normal * @@ -208,6 +157,30 @@ } } + /** + * This method copies the values of the request parameters richTextOnlineInstructions + * richTextOfflineInstructions richTextContent into the form properties + * onlineInstructions, offlineInstructions and content respectively. + * If a null value is returned for the request parameter, the form value is not modified. + * The request parameters are set as optional because the form spans amongst two pages. + * + * @param request HttpServlet request + * @param form The ActionForm class containing data submitted by the forms. + */ + private void copyInstructionFormProperty(HttpServletRequest request, NbAuthoringForm form) + { + String onlineInstruction = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN, true); + String offlineInstruction = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN, true); + String content = WebUtil.readStrParam(request, NoticeboardConstants.RICH_TEXT_CONTENT, true); + + if(content != null) + form.setContent(content); + if(onlineInstruction != null) + form.setOnlineInstructions(onlineInstruction); + if(offlineInstruction != null) + form.setOfflineInstructions(offlineInstruction); + + } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringStarterAction.java =================================================================== diff -u -rdeeaba2ec6d90361b2d8a53dc36ef14793e08caa -r3f27eea9deb1424106b5397c4559d3f609416399 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringStarterAction.java (.../NbAuthoringStarterAction.java) (revision deeaba2ec6d90361b2d8a53dc36ef14793e08caa) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/NbAuthoringStarterAction.java (.../NbAuthoringStarterAction.java) (revision 3f27eea9deb1424106b5397c4559d3f609416399) @@ -22,8 +22,6 @@ /* * Created on May 19, 2005 * @author mtruong - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates */ package org.lamsfoundation.lams.tool.noticeboard.web; @@ -49,15 +47,17 @@ import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException; +import org.lamsfoundation.lams.util.WebUtil; + /** * Creation Date: 19-05-05 * * ----------------XDoclet Tags-------------------- * * @struts:action path="/tool/nb/starter/authoring" name="NbAuthoringForm" scope="session" type="org.lamsfoundation.lams.tool.noticeboard.web.NbAuthoringStarterAction" - * input="/index.jsp" validate="false" + * input=".authoringStarter" validate="false" * @struts:action-forward name="basic" path=".nb_basic" * ----------------XDoclet Tags-------------------- */ @@ -83,15 +83,15 @@ NbAuthoringForm nbForm = (NbAuthoringForm)form; - Long contentId = NbAuthoringUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID)); - + // Long contentId = NbAuthoringUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID)); + Long contentId = NbAuthoringUtil.convertToLong(nbForm.getToolContentId()); if(contentId == null) { String error = "Tool content id missing. Unable to continue."; throw new NbApplicationException(error); } - NbAuthoringUtil.cleanSession(request); + NbAuthoringUtil.cleanSession(request); /** TODO: remove this, info no longer stored in session, using ActionForms instead */ request.getSession().setAttribute(NoticeboardConstants.TOOL_CONTENT_ID, contentId); @@ -106,24 +106,20 @@ NoticeboardContent nb = nbService.retrieveNoticeboard(NoticeboardConstants.DEFAULT_CONTENT_ID); //create a new noticeboard object and prefill with default content, save to database - NoticeboardContent nbContentNew = new NoticeboardContent(); + NoticeboardContent nbContentNew = new NoticeboardContent(contentId, + nb.getTitle(), + nb.getContent(), + nb.getOnlineInstructions(), + nb.getOfflineInstructions(), + new Date(System.currentTimeMillis())); - nbContentNew.setNbContentId(contentId); - nbContentNew.setDateCreated(new Date(System.currentTimeMillis())); - nbContentNew.setTitle(nb.getTitle()); - nbContentNew.setContent(nb.getContent()); - nbContentNew.setOnlineInstructions(nb.getOnlineInstructions()); - nbContentNew.setOfflineInstructions(nb.getOfflineInstructions()); - //save new tool content into db nbService.saveNoticeboard(nbContentNew); //initialise the values in the form, so the values will be shown in the jsp nbForm.populateFormWithNbContentValues(nbContentNew); - setValueForRichTextContent(request, nbForm); - setValueForRichTextOnlineInstrn(request, nbForm); - setValueForRichTextOfflineInstrn(request, nbForm); + } else { @@ -132,10 +128,7 @@ nbForm.populateFormWithNbContentValues(nb); - setValueForRichTextContent(request, nbForm); - setValueForRichTextOnlineInstrn(request, nbForm); - setValueForRichTextOfflineInstrn(request, nbForm); - + } return mapping.findForward(NoticeboardConstants.BASIC_PAGE); @@ -156,48 +149,6 @@ return true; } - /** - * If the content attribute of the noticeboard object is NULL - * then the session attribute richTextContent is set to an empty string. - * Otherwise, richTextContent takes on the the value of content - * and is stored in the session - * @param request - * @param form - */ - private void setValueForRichTextContent(HttpServletRequest request, NbAuthoringForm form) - { - if (form.getContent() != null) - { - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_CONTENT, form.getContent()); - } - else - { - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_CONTENT, ""); - } - } - private void setValueForRichTextOnlineInstrn(HttpServletRequest request, NbAuthoringForm form) - { - if (form.getOnlineInstructions() != null) - { - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN, form.getOnlineInstructions()); - } - else - { - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_ONLINE_INSTRN, ""); - } - } - private void setValueForRichTextOfflineInstrn(HttpServletRequest request, NbAuthoringForm form) - { - if (form.getOfflineInstructions() != null) - { - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN, form.getOfflineInstructions()); - } - else - { - request.getSession().setAttribute(NoticeboardConstants.RICH_TEXT_OFFLINE_INSTRN, ""); - } - } - } \ No newline at end of file