1.前端调用

$.ajax({
    url:"${request.contextPath}/web/json/plugin/com.vps.menu.ShortcutButton/service?uvId="+UI.userview_id,
    data:{},
    method:'GET',
    dataType:'text',
    async:false,
    success:function(html){
        console.log("html",html)
        
    },
    error:function(err){
        console.error("err",err)
    }
})
UI.userview_id 是Joget内置的JS API,可以直接使用,参考 JavascriptAPI https://dev.joget.org/community/display/DX7/Javascript+API#JavascriptAPI-UI


2.根据UserviewId获取Userview

String uvId = httpServletRequest.getParameter("uvId");
Map<String, Object> properties = getUserviewPropertiesByUserviewId(httpServletRequest,uvId);


/**
 * 获取用户界面插件配置项属性值
 * @param request
 * @param userviewId
 * @return
 */
public Map<String, Object> getUserviewPropertiesByUserviewId(HttpServletRequest request,String userviewId) {
    AppDefinition appDef=AppUtil.getCurrentAppDefinition();
    UserviewDefinitionDao userviewDefinitionDao = (UserviewDefinitionDao)AppUtil.getApplicationContext().getBean("userviewDefinitionDao");
    UserviewDefinition userviewDef = userviewDefinitionDao.loadById(userviewId, appDef);
    if (userviewDef != null) {
        String json = userviewDef.getJson();
        Map<String, Object> properties = new HashMap<>();
        try {
            JSONObject userviewObj = new JSONObject(json);
            JSONArray categoriesArray = userviewObj.getJSONArray("categories");
            for(int i = 0; i < categoriesArray.length(); ++i) {
                JSONObject categoryObj = (JSONObject)categoriesArray.get(i);
                JSONArray menusArray = categoryObj.getJSONArray("menus");
                for(int j = 0; j < menusArray.length(); ++j) {
                    JSONObject menuObj = (JSONObject)menusArray.get(j);
                    if (menuObj.getString("className").equalsIgnoreCase(getClassName())){
                        properties = PropertyUtil.getProperties(menuObj.getJSONObject("properties"));
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        for (String s : properties.keySet()) {
            LogUtil.info("key: "+s, "val:"+properties.get(s));
        }
        // 放置到抽象类中,后续可以直接使用 getProperty 获取
        setProperties(properties);
        return properties;
    }
    return null;
}
  • No labels