I am developing the JSP portlet using plugin sdk.
I want to implement AJAX in this portlet.
I am facing the problem while sending the URL in
jQuery.ajax({
type: "GET",
url: "/changemode.jsp",
data: "modeVal=rahul",
success: function(msg){
alert( "Data Saved: " + msg );
}});
the changemode.jsp is @ same location as the calling JSP.
It doest show any error msg, but the changemode.jsp is not get called.
Please advice.
Thanks in advance.
------------------------------------------------------------------------------------
you need to pass url like that
var url = '<portlet:renderURL
windowState="<%= LiferayWindowState.EXCLUSIVE.toString()
%>"><portlet:param name="struts_action"
value="/ext/search/changemode" /></portlet:renderURL>';
and struts action entry should be in struts-config.xml and tiles-defs.xml
-------------------------------------------------------------------------------------
Use the serveResource()
method (javax.portlet.GenericPortlet):
1
public void serveResource(ResourceRequest request, ResourceResponse response)
2
throws PortletException, IOException {
3
4
// Make the parameter "modeVal" available in changeMode.jsp
5
String modeVal = ParamUtil.getString(request, "modeVal");
6
request.setAttribute("modeVal", modeVal);
7
8
// Dispatch to changeMode.jsp
9
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(
10
"/WEB-INF/jsp/changeMode.jsp");
11
dispatcher.include(request, response);
12
}
In your jsp, set the url to <portlet:resourceURL/>
:
1
jQuery.ajax({
2
type: "GET",
3
url: "<portlet:resourceURL />",
4
data: "modeVal=rahul",
5
success: function(msg){
6
alert( "Data Saved: " + msg );
7
}});
If you need to handle dispatching to more than one page, specify an id
like this:
1
<portlet:resourceURL id="changeMode" />
Check the id
in serveResource()
to decide where to dispatch the request.
1
if( request.getResourceID().equals("changeMode")) {
2
. . .
3
}
-------------------------------------------------------------------------------------
It is really helpful .... now i'm one step ahead ...
I have some question regarding serveResource() method .....
1. should i write a servlet class which extends form GenericServlet and implement serveResource() method.
2. But in that case while calling that servlet from jsp with url <portlet:resourceURL /> what
should my url mapping of <servlet-mapping> in web.xml
3. Is it possible to set session a value in the same servlet and use it later.
4. On which object should i set session. PortletSession or HttpSession.
-------------------------------------------------------------------------------------------
Hi Rahul, good to hear that you're making progress!
Now, for your additional questions ...
1. Extend
javax.portlet.GenericPortlet
, example:
1
package com.example.portal.test.ajax;
2
3
import java.io.IOException;
4
5
import javax.portlet.GenericPortlet;
6
import javax.portlet.PortletException;
7
import javax.portlet.PortletRequestDispatcher;
8
import javax.portlet.RenderRequest;
9
import javax.portlet.RenderResponse;
10
import javax.portlet.ResourceRequest;
11
import javax.portlet.ResourceResponse;
12
13
import com.liferay.portal.kernel.util.ParamUtil;
14
15
public class AjaxPortlet extends GenericPortlet {
16
17
@Override
18
public void serveResource(ResourceRequest request, ResourceResponse response)
19
throws PortletException, IOException {
20
21
// Make the parameter "modeVal" available in changeMode.jsp
22
String modeVal = ParamUtil.getString(request, "modeVal");
23
request.setAttribute("modeVal", modeVal);
24
25
// Dispatch to changeMode.jsp
26
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(
27
"/WEB-INF/jsp/changeMode.jsp");
28
dispatcher.include(request, response);
29
}
30
31
@Override
32
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
33
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/view.jsp");
34
dispatcher.include(request, response);
35
}
36
37
}
2. Specify the above
portlet
class in
/WEB-INF/portlet.xml
:
1
<portlet-class>com.example.portal.test.ajax.AjaxPortlet</portlet-class>
3.
and 4. If you're not using servlets in your application, use
PortletSession. If you need to share session between servlet and
portlet, refer to
this
article.
---------------------------------------------------------------------------------
but now i'm confused because i already have an entry in portlet.xml for <portlet-class> so,
can a portlet have more than one <portlet-class> and if yes what property needs to be set.
If not then can you suggest any other way ....
--------------------------------------------------------------------------------
You cannot have more than one entry for <portlet-class> in portlet.xml
Is your existing entry
com.liferay.util.bridges.MVCPortlet
? This class extends LiferayPortlet which extends GenericPortlet. MVCPortlet implements serveResource() like this:
1
public void serveResource(
2
ResourceRequest resourceRequest, ResourceResponse resourceResponse)
3
throws IOException, PortletException {
4
5
String jspPage = resourceRequest.getParameter("jspPage");
6
7
if (jspPage != null) {
8
include(
9
jspPage, resourceRequest, resourceResponse,
10
PortletRequest.RESOURCE_PHASE);
11
}
12
else {
13
super.serveResource(resourceRequest, resourceResponse);
14
}
15
}
If
this does not suit your needs, you have to replace the entry in
<portlet-class> with your own extension of GenericPortlet (e.g.,
AjaxPortlet).
--------------------------------------------------------------------------------
分享到:
相关推荐
国界shapefile矢量数据,分为大陆界和海岸线,同时包含了未定国界和九段线。分为三个图层,可供作图使用,ArcGIS等作图软件打开即用
未定
无效合同与效力未定合同有什么区别.pdf
108系列柴油机技术条件-未定版..pdf
面对智能家居,运营商举棋未定!.pdf
SST前锋:北汽新能源借壳上市日期未定.pdf
新物流专题-即时配送、新兴市场、格局未定.pdf
新浪科技讯 4月26日上午消息,百度CEO李彦宏今日表示,中国互联网虽然经过十几年发展,但大局仍然未定、好戏还在后面。他表示互联网应继续向商业化发展,以便更好的拉动经济。此外,李彦宏称将进一步推动开放平台...
与碳排量相关的未定权益的计算,杨晓丽,梁进,根据《京都议定书》对发达国家的碳减排义务进行的规定,本文预测了某国到期碳排放量超过限额的概率,并计算由此可能产生的政策性
论文研究-借贷利率不同情形下具有随机寿命的未定权益定价.pdf, 在借贷利率不同情形下 ,首先得到随机寿命的未定权益价格应满足的偏微分方程 ;其次对具有随机寿命的远期...
有色行业周观点报告:金属价格承压 贸易协议仍未定.pdf
运用未定权益分析方法,给出风险债务估值的基本思路及风险债务价值满足的微分方程,得到永久性债务估值模型,可作为长期债务估值的近似。运用未定权益定价和随机计算方法,导出了一个包含破产成本的风险债务估值公式...
合同法——比较效力未定合同、可撤销合同、无效合同的区别.pdf
商业贸易行业:社区团购,下沉市场风口再起,群雄逐鹿乾坤未定
2021年中国网约车行业研究报告 -竞争格局打破重组未定,行业规范亟需加强.pdf
论文研究-未定路网结构情况下应急物资车辆配送问题模型与应用.pdf, 重大自然灾害往往毁损当地交通道路,现有应急物资车辆配送问题的研究,均是只考虑未受损道路构成的路网...
标题未定
物业管理行业专题研究:赛道宽广,盈利提升,格局未定-20200904-中信证券-30页.pdf
社区团购,下沉市场风口再起,群雄逐鹿乾坤未定-2020.12.8-35页精品报告2020.pdf