日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Liferay Portal額外研究(五):對(duì)多分發(fā)命令A(yù)c

系統(tǒng) 1923 0
?Liferay默認(rèn)提供的基于 Struts Action擴(kuò)展的PortletAction是不支持多分發(fā)命令的,也就是我們一般常用的DispatchAction。 但在我們?nèi)粘;? Struts處理的操作中,已經(jīng)大量的沿用了DispatchAction處理方式,采用“cmd=queryall”諸如此類的方式。
??? 本文就來給大家講解如何通過擴(kuò)展,讓 Liferay實(shí)現(xiàn)對(duì)多分發(fā)命令A(yù)ction的支持。
?
??? 首先讓我們來看看 Liferay是如何處理的:
? ??? portlet.xml中,我們一般會(huì)配置如下:
< portlet-class > com.liferay.portlet.StrutsPortlet </ portlet-class >
< init-param >
????
< name > view-action </ name >
????
< value > /ext/reports/view_reports </ value >
</ init-param >
?
?????? 這樣 Liferay面對(duì)一個(gè)Portlet請(qǐng)求的時(shí)候,會(huì)根據(jù)請(qǐng)求model來執(zhí)行Portlet的doView或doEdit方式。當(dāng)執(zhí)行doView的時(shí)候就會(huì)請(qǐng)求其view-action所配置的Action URL所代表的Action來處理。
????? 其處理流程大致是: Portlet類——〉RequestProcessor——〉StrutsAction處理類
?
???? 我們可以通過兩種擴(kuò)展方案來實(shí)現(xiàn)對(duì)多分發(fā)的支持:
??? ? 方案(一): 擴(kuò)展 Liferay的StrutsPortlet類,并寫一個(gè)DispatchPortletAction類,這樣不用擴(kuò)展RequestProcessor實(shí)現(xiàn)。
???? 方案(二): 擴(kuò)展 RequestProcessor 與,并寫一個(gè)DispatchPortletAction類,這樣可以直接使用Liferay所提供的StrutsPortlet類。對(duì)于 RequestProcessor的擴(kuò)展,在通過portal.properties文件中通過配置 “struts.portlet.request.processor”屬性來設(shè)置。
?
??? 接下來就兩種方案做分別的詳細(xì)講解(本篇先講方案一):
?
方案(一)
?
首先讓我們寫一個(gè) DispatchPortletAction 類,此類可以通過擴(kuò)展Liferay本身的PortletAction實(shí)現(xiàn),也可以通過擴(kuò)展Struts本身的DispatchAction實(shí)現(xiàn)。本人是選擇后一種方式,這樣擴(kuò)展的代碼量較少,都不要自己寫execute方式,直接使用基類的即可。
對(duì)于 DispatchPortletAction 主要擴(kuò)展dispatchMethod和getMethodName方法。注意在getMechodName方法中,還追加了從 request.getAttribute(parameter)獲取方法名稱,并注意unspecified方法,這個(gè)是在沒有指明訪問方法的時(shí)候默認(rèn)執(zhí)行的,所以開發(fā)人員在后續(xù)寫自己的Action一定要實(shí)現(xiàn)這個(gè)。

public ? class ?DispatchPortletAction? extends ?DispatchAction? ... {
????
protected ?ActionForward?dispatchMethod(ActionMapping?mapping,
????????????ActionForm?form,?HttpServletRequest?request,
????????????HttpServletResponse?response,?String?name)?
throws ?Exception? ... {

????????PortletConfig?portletConfig?
= ?(PortletConfig)?request
????????????????.getAttribute(WebKeys.JAVAX_PORTLET_CONFIG);

????????RenderRequest?renderRequest?
= ?(RenderRequest)?request
????????????????.getAttribute(WebKeys.JAVAX_PORTLET_REQUEST);

????????RenderResponse?renderResponse?
= ?(RenderResponse)?request
????????????????.getAttribute(WebKeys.JAVAX_PORTLET_RESPONSE);

????????
if ?(name? == ? null )? ... {
????????????
return ? this .unspecified(mapping,?form,?portletConfig,
????????????????????renderRequest,?renderResponse);
????????}


????????Method?method?
= ? null ;
????????
try ? ... {
????????????method?
= ?getMethod(name);

????????}
? catch ?(NoSuchMethodException?e)? ... {
????????????String?message?
= ?messages.getMessage( " dispatch.method " ,
????????????????????mapping.getPath(),?name);
????????????log.error(message,?e);

????????????String?userMsg?
= ?messages.getMessage( " dispatch.method.user " ,
????????????????????mapping.getPath());
????????????
throw ? new ?NoSuchMethodException(userMsg);
????????}


????????ActionForward?forward?
= ? null ;
????????
try ? ... {
????????????Object?args[]?
= ? ... {?mapping,?form,?portletConfig,?renderRequest,
????????????????????renderResponse?}
;
????????????forward?
= ?(ActionForward)?method.invoke( this ,?args);

????????}
? catch ?(ClassCastException?e)? ... {
????????????String?message?
= ?messages.getMessage( " dispatch.return " ,
????????????????????mapping.getPath(),?name);
????????????log.error(message,?e);
????????????
throw ?e;

????????}
? catch ?(IllegalAccessException?e)? ... {
????????????String?message?
= ?messages.getMessage( " dispatch.error " ,
????????????????????mapping.getPath(),?name);
????????????log.error(message,?e);
????????????
throw ?e;

????????}
? catch ?(InvocationTargetException?e)? ... {
????????????Throwable?t?
= ?e.getTargetException();
????????????
if ?(t? instanceof ?Exception)? ... {
????????????????
throw ?((Exception)?t);
????????????}
? else ? ... {
????????????????String?message?
= ?messages.getMessage( " dispatch.error " ,
????????????????????????mapping.getPath(),?name);
????????????????log.error(message,?e);
????????????????
throw ? new ?ServletException(t);
????????????}

????????}

????????
return ?(forward);
????}


????
protected ?String?getMethodName(ActionMapping?mapping,?ActionForm?form,
????????????HttpServletRequest?request,?HttpServletResponse?response,
????????????String?parameter)?
throws ?Exception? ... {

????????String?methodName?
= ?request.getParameter(parameter);
????????
if ?(methodName? == ? null ? || ?methodName.length()? == ? 0 )? ... {
?????????????methodName?
= ?(String)?request.getAttribute(parameter);
????????}

????????
return

Liferay Portal額外研究(五):對(duì)多分發(fā)命令A(yù)ction的支持(方案一)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 江安县| 涿鹿县| 吉安县| 乌拉特前旗| 盐亭县| 新巴尔虎左旗| 南京市| 南漳县| 阳原县| 内黄县| 三门县| 牡丹江市| 乌拉特中旗| 静乐县| 稻城县| 资阳市| 平湖市| 洛扎县| 金山区| 沙洋县| 永仁县| 元江| 鹿邑县| 全椒县| 开平市| 大同县| 芜湖县| 福安市| 衡南县| 获嘉县| 吉水县| 灯塔市| 克东县| 昌图县| 绿春县| 舞阳县| 区。| 淳化县| 丹棱县| 新干县| 洛隆县|