import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;
import com.autotoll.jv.erp.proxy.PortletActionBeanProxy;
import com.autotoll.jv.erp.util.ErpStatus;
import com.autotoll.jv.pojo.impl.UserInfo;
import com.liferay.portal.json.JSONArrayImpl;
import com.liferay.portal.json.JSONObjectImpl;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.model.User;
import com.liferay.portal.struts.AJAXAction;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.WebKeys;
public class GetCustNodeAjax extends AJAXAction{
@SuppressWarnings("unchecked")
public String getText(ActionMapping arg0, ActionForm arg1,
HttpServletRequest req, HttpServletResponse response) throws Exception {
ThemeDisplay themeDisplay =
(ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
User user = themeDisplay.getUser();
UserInfo userInfo = PortletActionBeanProxy.
getInstance().getUserInfoSvc().
findUserInfoById(user.getUuid());
String lanageId = themeDisplay.getLanguageId();
String custId = req.getParameter("custId");
//货源地
String s_type = ErpStatus.COMP_NODE_HUOYUAN;
List<Map<String, Object>> s_cityList = PortletActionBeanProxy.
getInstance().getCityTableSvc().
findCityTableByNodeId(new Integer(custId),
userInfo.getCompInfo().getCompId(), new Short(s_type));
//目的地
String d_type = ErpStatus.COMP_NODE_MUDIDI;
List<Map<String, Object>> d_cityList = PortletActionBeanProxy.
getInstance().getCityTableSvc().
findCityTableByNodeId(new Integer(custId),
userInfo.getCompInfo().getCompId(), new Short(d_type));
JSONObject jsonObj = new JSONObject();
//货源地和目的地
jsonObj = createJson(s_cityList,d_cityList,lanageId);
//System.out.println("json----"+jsonObj.toString());
return jsonObj.toString();
}
/**
* 创建json
* @param list
* @param lanageId
*/
private JSONObject createJson(List<Map<String,Object>> s_list,
List<Map<String,Object>> d_list,String lanageId){
JSONObject jsonObj = new JSONObject();
JSONObjectImpl jsonImpl = new JSONObjectImpl();
JSONArray s_jsonArrId = new JSONArrayImpl();
JSONArray s_jsonArrAdr = new JSONArrayImpl();
//货源地
if (s_list !=null && s_list.size()>0){
for(int i=0;i<s_list.size();i++) {
Map<String, Object> map = new HashMap<String, Object>();
map = s_list.get(i);
String custNodeId = String.valueOf(map.get("0"));
String proName_tc = String.valueOf(map.get("1"));
String proName_en = String.valueOf(map.get("2"));
String proName_sc = String.valueOf(map.get("3"));
String cityName_tc = String.valueOf(map.get("4"));
String cityName_en = String.valueOf(map.get("5"));
String cityName_sc = String.valueOf(map.get("6"));
String nodeAdr = String.valueOf(map.get("7"));
s_jsonArrId.put(custNodeId);
jsonImpl.put("s_custNodeId", s_jsonArrId);
if (lanageId.equals("zh_CN")) {
s_jsonArrAdr.put(proName_sc+cityName_sc+nodeAdr);
} else if (lanageId.equals("zh_TW")){
s_jsonArrAdr.put(proName_tc+cityName_tc+nodeAdr);
}else {
s_jsonArrAdr.put(proName_en+cityName_en+nodeAdr);
}
}
}
//目的地
JSONArray d_jsonArrId = new JSONArrayImpl();
JSONArray d_jsonArrAdr = new JSONArrayImpl();
if (d_list !=null && d_list.size()>0){
for(int i=0;i<d_list.size();i++) {
Map<String, Object> map = new HashMap<String, Object>();
map = d_list.get(i);
String custNodeId = String.valueOf(map.get("0"));
String proName_tc = String.valueOf(map.get("1"));
String proName_en = String.valueOf(map.get("2"));
String proName_sc = String.valueOf(map.get("3"));
String cityName_tc = String.valueOf(map.get("4"));
String cityName_en = String.valueOf(map.get("5"));
String cityName_sc = String.valueOf(map.get("6"));
String nodeAdr = String.valueOf(map.get("7"));
d_jsonArrId.put(custNodeId);
if (lanageId.equals("zh_CN")) {
d_jsonArrAdr.put(proName_sc+cityName_sc+nodeAdr);
} else if (lanageId.equals("zh_TW")){
d_jsonArrAdr.put(proName_tc+cityName_tc+nodeAdr);
}else {
d_jsonArrAdr.put(proName_en+cityName_en+nodeAdr);
}
}
}
jsonImpl.put("s_address", s_jsonArrAdr);
jsonImpl.put("s_custNodeId", s_jsonArrId);
jsonImpl.put("d_custNodeId", d_jsonArrId);
jsonImpl.put("d_address", d_jsonArrAdr);
jsonImpl.put("totalNum", s_list.size()+d_list.size());
jsonObj = jsonImpl.getJSONObject();
return jsonObj;
}
}
jsp 页面:
function getCustNodeList(obj){
var custId = obj.options[obj.selectedIndex].value;
var starSelect = document.getElementById('startNodeList');
var deSelect = document.getElementById('detionNodeList');
if(custId != "choose" && custId !="") {
jQuery.ajax(
{url: '<%= themeDisplay.getPathMain() %>/erp/getJson',
data: {custId:custId},
success: setCustNode});
} else {
starSelect.options.length = 0;
deSelect.options.length = 0;
starSelect.options.add(new Option("<liferay-ui:message key="erp.select.option.choose"/>","choose"));
deSelect.options.add(new Option("<liferay-ui:message key="erp.select.option.choose"/>","choose"));
}
}
function setCustNode(json) {
var jsonFile = eval('('+json+')');
var num = jsonFile.totalNum;
var starSelect = document.getElementById('startNodeList');
var deSelect = document.getElementById('detionNodeList');
starSelect.options.length = 0;
deSelect.options.length = 0;
for(var i=0 ;i<num-1 ;i++){
var s_custNodeId; var s_custNodeAdr;
var d_custNodeId; var d_custNodeAdr;
if(jsonFile.s_custNodeId != null) {
s_custNodeId = jsonFile.s_custNodeId[i];
}
if (jsonFile.s_address !=null) {
s_custNodeAdr = jsonFile.s_address[i];
}
if(jsonFile.s_address !=null && jsonFile.s_address !=null) {
starSelect.options.add(new Option(s_custNodeAdr,s_custNodeId));
}
if (jsonFile.d_custNodeId != null ) {
d_custNodeId = jsonFile.d_custNodeId[i];
}
if (jsonFile.d_address !=null) {
d_custNodeAdr = jsonFile.d_address[i];
}
if (jsonFile.d_custNodeId !=null && jsonFile.d_address != null) {
deSelect.options.add(new Option(d_custNodeAdr,d_custNodeId));
}
}
starSelect.options.add(new Option("<liferay-ui:message key="erp.select.option.choose"/>","choose"));
deSelect.options.add(new Option("<liferay-ui:message key="erp.select.option.choose"/>","choose"));
}
分享到:
相关推荐
在Liferay中,JSON Web服务提供了灵活的方式来交互和操作平台数据。这些服务允许开发者通过不同的方式调用,包括JavaScript、curl命令以及直接通过URL。以下是对这两种主要使用场景的详细说明: 1. **在Portlet中...
liferay,jquery,portlet,portal
1. **Struts2 JSON插件**:了解如何配置Struts2的json-plugin,使得Action可以直接返回JSON结果,而无需额外的视图层处理。 2. **Spring整合Struts2**:学习如何在Spring容器中管理Struts2的Action类,以及如何通过...
liferay-jquery-plugins Liferay 门户的 jQuery 插件 建造 启动并运行环境 克隆这个 repo git clone https://github.com/natecavanaugh/liferay-jquery-plugins.git 安装 安装 <sudo> npm install --global ...
最后,"plugins开发指南19-liferay6中使用JSON.pdf"解释了如何利用JSON进行数据交换,提高应用程序的响应速度和效率。 通过学习这些教程,开发者不仅可以掌握Liferay 6的基础知识,还能深入了解其插件开发、MVC架构...
Liferay Portal Liferay IDE
Liferay是一款开源的企业级门户平台,它提供了丰富的功能和高度可定制性,广泛应用于构建企业网站、内部系统、协作平台等。在这个“liferay详细讲解 liferay项目完全讲解”的资料包中,我们可以期待深入了解到关于...
标题 "Liferay扩展环境 Liferay Ext" 涉及到的是Liferay门户平台的一个关键概念,Liferay Ext是用于扩展和定制Liferay功能的核心工具。Liferay是一个开源的企业级内容管理平台,它允许用户根据需求构建自定义的数字...
将Liferay与Struts整合,可以充分利用Struts的业务逻辑处理能力和Liferay的门户管理特性,打造出高效、灵活的应用系统。 在这个"liferay 整合struts例子"中,我们可以学习到以下几个关键知识点: 1. **Liferay ...
在Liferay中,Hibernate常用于处理数据持久化。通过配置,开发者可以在Liferay中集成Hibernate,使得模型对象可以直接映射到数据库表,无需编写大量的SQL代码。Liferay的Service Builder工具也可以与Hibernate结合,...
### Liferay 6.0 开发指南核心知识点详解 #### 一、引言与概述 Liferay是一款功能强大且设计优秀的开源门户系统,其版本6.0尤其在多个方面进行了优化和完善,为开发者提供了更加友好和高效的工作环境。本指南旨在...
如果验证成功,CAS会将一个ticket返回给Liferay,Liferay再基于这个ticket确认用户的身份并允许其访问资源。 实现Liferay的CAS SSO主要包括以下步骤: 1. **安装和配置CAS服务器**:首先,你需要下载并部署CAS...
如果登录失败,你需要捕获并处理异常,向用户返回适当的错误消息。登录成功后,通常会重定向到默认的用户首页或特定页面。这可以通过设置`ActionResponse`的`setRedirect`方法实现。 6. **配置portlet** 在`...
《Liferay Portal 6.0.6 学习手册》是针对企业级开源门户平台Liferay Portal的一个详细学习指南,由作者李少华编写。本文将深入探讨Liferay Portal的基础知识,安装配置,源码分析,开发环境设置,以及基于Struts2的...
Liferay是一个基于Java Enterprise Edition (J2EE) 的应用,它整合了多种技术,如EJB (Enterprise JavaBeans) 和JMS (Java Message Service),用于后台处理和通信。在前端,Liferay采用了Struts MVC框架,增强了用户...
Struts2是一个强大的MVC框架,它提供了处理用户请求、业务逻辑和视图展示的能力,而Liferay则是一个开源的企业门户平台,能够方便地创建和管理数字体验。 在本项目中,“struts2+liferay集成”是通过Liferay IDE和...
### Liferay快速入门知识点详解 #### 一、Liferay Portal简介与快速启动 Liferay Portal是一款功能强大且灵活的企业级门户平台,它基于Java技术,遵循JSR-168标准,提供了丰富的特性来满足企业内外部网站的需求。...
### Liferay环境搭建详解 #### 一、简介 Liferay是一款功能强大的开源企业级门户平台,主要用于构建企业级Web应用程序和服务。本文档旨在详细介绍如何利用Eclipse集成开发环境(IDE)来搭建Liferay开发环境,并...
然而,随着JSON格式在Web服务中的广泛应用,Liferay开始重构其远程服务,引入了基于JSON的远程服务(JSONWS),使得开发者可以更加灵活地调用Liferay提供的各种服务。 ##### 2.2 2014年:Liferay Mobile SDK API ...
这个名为"Liferay合集.zip"的压缩包包含了多本关于Liferay的重要书籍,如《Liferay in Action》、《Liferay Portal Systems Development》和《Liferay User Interface Development》,以及一些中文文档,这些资源...