在renderPage方法中加入以下代码

	String userviewId = this.getUserview().getPropertyString("id");
      String key = this.getKey() != null ? this.getKey() : "";
      String menuId = this.getPropertyString("customId");
      if (menuId == null || menuId.trim().isEmpty()) {
         menuId = this.getPropertyString("id");
      }


//    String nonce = SecurityUtil.generateNonce(new String[]{"ResourceSchedulerUserview", appDef.getId(), appDef.getVersion().toString(), userviewId, key, menuId}, 3);
//
//    try {
//       nonce = URLEncoder.encode(nonce, "UTF-8");
//    } catch (Exception var22) {
//    }

//    model.put("nonce", nonce);
      String jsonUrl = "/web/json/app/" + appDef.getId() + "/" + appDef.getVersion() + "/plugin/com.vps.menu.TreeView/service";
      String queryString = WorkflowUtil.getHttpServletRequest().getQueryString();
      if (queryString != null) {
         jsonUrl = StringUtil.addParamsToUrl(jsonUrl, StringUtil.getUrlParams(queryString));
      }

      jsonUrl = StringUtil.addParamsToUrl(jsonUrl, "userviewId", userviewId);
      jsonUrl = StringUtil.addParamsToUrl(jsonUrl, "menuId", menuId);
      jsonUrl = StringUtil.addParamsToUrl(jsonUrl, "key", key);
//    jsonUrl = jsonUrl + "&_nonce=" + nonce;
	  //页面中请求该URL即可
      model.put("jsonUrl", jsonUrl);

在插件中加入以下三个核心方法 : 用于获取当前userview

protected UserviewMenu findUserviewMenuFromPreview(String json, String menuId, String contextPath, Map parameterMap, String key) throws BeansException {
   UserviewService userviewService = (UserviewService)AppUtil.getApplicationContext().getBean("userviewService");
   Userview userview = userviewService.createUserview(json, menuId, false, contextPath, parameterMap, key, true);
   UserviewMenu selectedMenu = this.findUserviewMenuInUserview(userview, menuId);
   return selectedMenu;
}

protected UserviewMenu findUserviewMenuInUserview(Userview userview, String menuId) {
   if (userview.getCurrent() != null && (menuId.equals(userview.getCurrent().getPropertyString("customId")) || menuId.equals(userview.getCurrent().getPropertyString("id")))) {
      return userview.getCurrent();
   } else {
      UserviewMenu selectedMenu = null;
      boolean found = false;
      Collection<UserviewCategory> categories = userview.getCategories();
      Iterator var6 = categories.iterator();

      while(var6.hasNext()) {
         UserviewCategory category = (UserviewCategory)var6.next();
         Collection<UserviewMenu> menus = category.getMenus();
         Iterator var9 = menus.iterator();

         while(var9.hasNext()) {
            UserviewMenu menu = (UserviewMenu)var9.next();
            if (menuId.equals(menu.getPropertyString("customId")) || menuId.equals(menu.getPropertyString("id"))) {
               selectedMenu = menu;
               found = true;
               break;
            }
         }

         if (found) {
            break;
         }
      }

      return selectedMenu;
   }
}

protected UserviewMenu findUserviewMenuFromDef(AppDefinition appDef, String userviewId, String menuId, String key, String contextPath, Map parameterMap) throws BeansException {
   UserviewMenu selectedMenu = null;
   UserviewService userviewService = (UserviewService)AppUtil.getApplicationContext().getBean("userviewService");
   UserviewDefinitionDao userviewDefinitionDao = (UserviewDefinitionDao)AppUtil.getApplicationContext().getBean("userviewDefinitionDao");
   UserviewDefinition userviewDef = (UserviewDefinition)userviewDefinitionDao.loadById(userviewId, appDef);
   if (userviewDef != null) {
      String json = userviewDef.getJson();
      Userview userview = userviewService.createUserview(json, menuId, false, contextPath, parameterMap, key, true);
      selectedMenu = this.findUserviewMenuInUserview(userview, menuId);
   }

   return selectedMenu;
}

在webservice方法中加入以下代码 :

	  UserviewMenu selectedMenu = null;
      String userviewId = request.getParameter("userviewId");
      String key = request.getParameter("key");
      String menuId = request.getParameter("menuId");
      String contextPath = request.getContextPath();
      Map parameterMap = request.getParameterMap();
      String json = request.getParameter("json");
      AppDefinition appDef = AppUtil.getCurrentAppDefinition();
//    String nonce = request.getParameter("_nonce");
//    if (!SecurityUtil.verifyNonce(nonce, new String[]{"ResourceSchedulerUserview", appDef.getAppId(), appDef.getVersion().toString(), userviewId, key, menuId})) {
//       response.setStatus(403);
//       return;
//    }
      if (json != null && !json.trim().isEmpty()) {
         selectedMenu = this.findUserviewMenuFromPreview(json, menuId, contextPath, parameterMap, key);
      } else {
         selectedMenu = this.findUserviewMenuFromDef(appDef, userviewId, menuId, key, contextPath, parameterMap);
      }
      this.setProperties(selectedMenu.getProperties());

添加完成之后 , 可以使用this.getPropertyString("key")来获取userview的配置项

  • No labels