Thanks Matt. The page currently isn't being displayed at all, I'm getting a null pointer exception. I'll have a look at the link tonight.
Aled -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Matt Raible Sent: 20 August 2007 22:56 To: [email protected] Subject: Re: [appfuse-user] Getting my head around pickList Is your UI getting populated correctly? If so, then you have everything setup correctly from a pickList point of view. As far as needing a custom PropertyEditor - you'll need one if you want the ids in your pickList's right-hand side to turn into fully-composed objects. The following article may help you do that: http://www.jroller.com/raible/entry/multiple_select_with_spring_mvc Matt On 8/20/07, Aled Rhys Jones <[EMAIL PROTECTED]> wrote: > Thanks Matt, that makes sense. > Can you see anything obviously wrong with the below code? What I am > most unsure about is if I need a custom binder to bind between available > website types in the pick list and the list of website type objects in > the website object. > > Cheers > Aled > Matt Raible wrote: > > The "availableRoles" List is populated in StartupListener.java: > > > > /** > > * This method uses the LookupManager to lookup available roles > > from the data layer. > > * @param context The servlet context > > */ > > public static void setupContext(ServletContext context) { > > ApplicationContext ctx = > > WebApplicationContextUtils.getRequiredWebApplicationContext(context); > > LookupManager mgr = (LookupManager) ctx.getBean("lookupManager"); > > > > // get list of possible roles > > context.setAttribute(Constants.AVAILABLE_ROLES, mgr.getAllRoles()); > > log.debug("Drop-down initialization complete [OK]"); > > } > > > > You should be able to put a list of objects in any scope in your > > controller to do the same thing. The referenceData() method is a > > recommended location. > > > > Matt > > > > On 8/20/07, Aled Rhys Jones <[EMAIL PROTECTED]> wrote: > > > >> Any ideas guys? > >> > >> Aled Rhys Jones wrote: > >> > >>> Hi all > >>> > >>> I'm trying to get my head around the may to many pickList. I've got a > >>> many to many relationship between a website model and a website type > >>> model. > >>> The pick list used in the user form seems suitbable, but when I try to > >>> use it I get Null Pointer (jasper) exceptions. > >>> Questions: > >>> Where do availableRoles in userform.jsp get populated? > >>> UserFormController doesn't seem to be doing this. > >>> Do I need a bind a customeditor to get from strings to ids? What > >>> should I bind to? > >>> > >>> Thanks in advance for any help. > >>> > >>> Cheers > >>> Aled > >>> > >>> p.s. my jsp snippet: > >>> <c:choose> > >>> <c:when test="${not empty website.id}"> > >>> <li> > >>> <fieldset class="pickList"> > >>> <legend><fmt:message > >>> key="websiteForm.assignWebsiteTypes"/></legend> > >>> <table class="pickList"> > >>> <tr> > >>> <th class="pickLabel"> > >>> <appfuse:label > >>> key="websiteForm.availableWebsiteTypes" colon="false" > >>> styleClass="required"/> > >>> </th> > >>> <td></td> > >>> <th class="pickLabel"> > >>> <appfuse:label > >>> key="websiteForm.currentWebsiteTypes" colon="false" > >>> styleClass="required"/> > >>> </th> > >>> </tr> > >>> <c:set var="leftList" > >>> value="${availableWebsiteTypes}" scope="request"/> > >>> <c:set var="rightList" > >>> value="${website.websiteTypes}" scope="request"/> > >>> <c:import url="/WEB-INF/pages/pickList.jsp"> > >>> <c:param name="listCount" value="1"/> > >>> <c:param name="leftId" > >>> value="availableWebsiteTypes"/> > >>> <c:param name="rightId" value="websiteTypes"/> > >>> </c:import> > >>> </table> > >>> </fieldset> > >>> </li> > >>> <li> > >>> <strong><appfuse:label > >>> key="websiteForm.currentWebsiteTypes"/>:</strong> > >>> <c:forEach var="websiteType" > >>> items="${website.websiteTypes}" varStatus="status"> > >>> <c:out value="${websiteType.label}"/><c:if > >>> test="${!status.last}">,</c:if> > >>> <input type="hidden" name="websiteTypes" > >>> value="<c:out value="${websiteType.label}"/>"/> > >>> </c:forEach> > >>> </li> > >>> </c:when> > >>> <c:otherwise> > >>> <li> > >>> <p><fmt:message key="websiteForm.saveWebsiteTypes"/></p> > >>> </li> > >>> </c:otherwise> > >>> > >>> My fromcontroller (so far): > >>> private WebsiteManager websiteManager = null; > >>> private CountryManager countryManager = null; > >>> private UserManager userManager = null; > >>> private WebsiteTypeManager websiteTypeManager = null; > >>> public void setWebsiteManager(WebsiteManager websiteManager) { > >>> this.websiteManager = websiteManager; } > >>> public void setCountryManager(CountryManager countryManager) { > >>> this.countryManager = countryManager; } > >>> public void setUserManager(UserManager userManager){ > >>> this.userManager = userManager; > >>> } > >>> public void setWebsiteTypeManager(WebsiteTypeManager > >>> websiteTypeManager){ > >>> this.websiteTypeManager = websiteTypeManager; > >>> } > >>> > >>> public WebsiteFormController() { > >>> setCommandClass(Website.class); setCommandName("website"); } > >>> protected Object formBackingObject(HttpServletRequest request) > >>> throws Exception { String id = request.getParameter("id"); > >>> Website website; > >>> if (!StringUtils.isBlank(id)) { > >>> website = websiteManager.get(new Long(id)); } > >>> else{ > >>> website = new Website(); > >>> Url url = new Url(); > >>> website.setUrl(url); > >>> Contact contact = new Contact(); > >>> website.setContact(contact); > >>> } > >>> return website; > >>> } > >>> public ModelAndView onSubmit(HttpServletRequest request, > >>> HttpServletResponse response, Object > >>> command, BindException errors) > >>> throws Exception { log.debug("entering 'onSubmit' method..."); > >>> Website website = (Website) command; boolean isNew = > >>> (website.getId() == null); String success = getSuccessView(); > >>> Locale locale = request.getLocale(); if > >>> (request.getParameter("delete") != null) { > >>> websiteManager.remove(website.getId()); > >>> saveMessage(request, getText("websiteForm.deleted", locale)); > >>> } else { > >>> String key = (isNew) ? "websiteForm.added" : > >>> "websiteForm.updated"; > >>> User requestUser = > >>> userManager.getUserByUsername(request.getRemoteUser()); > >>> if(request.getParameter("disapprove") != null){ > >>> website.setIsChecked(false); > >>> website.setCheckedUser(null); > >>> } > >>> else if(request.getParameter("approve") != null){ > >>> website.setIsChecked(true); > >>> website.setCheckedUser(requestUser); > >>> } > >>> if (!isNew) { > >>> success = "redirect:websiteform.html?id=" + > >>> website.getId(); > >>> String[] selectedWebsiteTypes = > >>> request.getParameterValues("websiteTypes"); > >>> > >>> if (selectedWebsiteTypes != null) { > >>> List<WebsiteType> websiteTypes = new > >>> ArrayList<WebsiteType>(); > >>> for (String websiteType : selectedWebsiteTypes) { > >>> > >>> websiteTypes.addAll(websiteTypeManager.findByType(websiteType)); > >>> } > >>> website.setWebsiteTypes(websiteTypes); > >>> } > >>> > >>> } else{ > >>> website.setSubmittedUser(requestUser); > >>> } > >>> websiteManager.save(website); > >>> saveMessage(request, getText(key, locale)); > >>> } > >>> return new ModelAndView(success); } > >>> protected Map referenceData(HttpServletRequest request) throws > >>> Exception { > >>> Map<String, Object> retval = new HashMap<String, Object>(); > >>> retval.put("countries", countryManager.getAll()); > >>> retval.put("availableWebsiteTypes", websiteTypeManager.getAll()); > >>> return retval; > >>> } > >>> @Override > >>> protected void initBinder(HttpServletRequest request, > >>> ServletRequestDataBinder binder) { > >>> binder.registerCustomEditor(Country.class, "contact.country", > >>> new CountryEditor(countryManager)); > >>> binder.registerCustomEditor(Set.class, "websiteTypes", new > >>> CustomCollectionEditor(Set.class) { > >>> protected Object convertElement(Object element) { > >>> if (element != null) { > >>> Long id = new Long((String)element); > >>> WebsiteType websiteType = websiteTypeManager.get(id); > >>> return websiteType; > >>> } > >>> return null; > >>> } > >>> }); > >>> } > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>> For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >>> > >>> > >>> > >>> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- http://raibledesigns.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
