/connect-web/src/main/java/org/osforce/connect/web/module/commons/TagWidget.java

http://focus-sns.googlecode.com/ · Java · 74 lines · 57 code · 10 blank · 7 comment · 1 complexity · 25cbf9517b129e177725c942eea411f3 MD5 · raw file

  1. package org.osforce.connect.web.module.commons;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Map;
  5. import org.apache.commons.lang.math.NumberUtils;
  6. import org.osforce.connect.entity.commons.Tag;
  7. import org.osforce.connect.service.commons.TagService;
  8. import org.osforce.connect.web.AttributeKeys;
  9. import org.osforce.spring4me.commons.collection.CollectionUtil;
  10. import org.osforce.spring4me.dao.Page;
  11. import org.osforce.spring4me.web.bind.annotation.PrefParam;
  12. import org.osforce.spring4me.web.stereotype.Widget;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.ui.Model;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import org.springframework.web.context.request.WebRequest;
  20. /**
  21. *
  22. * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
  23. * @since 1.1.1
  24. * @create Jun 3, 2011 - 11:22:09 AM
  25. * <a href="http://www.opensourceforce.org">????</a>
  26. */
  27. @Widget
  28. @RequestMapping("/commons/tag")
  29. public class TagWidget {
  30. private TagService tagService;
  31. public TagWidget() {
  32. }
  33. @Autowired
  34. public void setTagService(TagService tagService) {
  35. this.tagService = tagService;
  36. }
  37. @RequestMapping("/list-view")
  38. public String doListView(@PrefParam String paramName,
  39. @PrefParam String entity, WebRequest request, Model model) {
  40. Long linkedId = NumberUtils.createLong(request.getParameter(paramName));
  41. List<Tag> tags = tagService.getTagList(linkedId, entity);
  42. model.addAttribute(AttributeKeys.TAG_LIST_KEY_READABLE, tags);
  43. return "commons/tag-list.ftl";
  44. }
  45. @RequestMapping(value="/delete-action", method=RequestMethod.GET)
  46. public @ResponseBody Object doDeleteAction(@RequestParam Long tagId) {
  47. tagService.deleteTag(tagId);
  48. return Collections.singletonMap("id", tagId);
  49. }
  50. @RequestMapping(value="/auto-action", method=RequestMethod.GET)
  51. public @ResponseBody Object autoComplete(@RequestParam String query) {
  52. Page<Tag> page = new Page<Tag>(10);
  53. page = tagService.getTagPage(page, query);
  54. Map<String, Object> model = CollectionUtil.newHashMap();
  55. model.put("query", query);
  56. model.put("data", "");
  57. List<String> suggestions = CollectionUtil.newArrayList();
  58. for(Tag tag : page.getResult()) {
  59. suggestions.add(tag.getName());
  60. }
  61. model.put("suggestions", suggestions);
  62. return model;
  63. }
  64. }