2012-04-09 4 views
1

6つのポートレットからなるページを定義し、portal-ext.propertiesファイルをデフォルトのLndingページとして設定しました。Liferay:LiferayでRequestDispatcherを使用してパブリックページにリダイレクトする方法

私は私のデータベースに接触させるためのカスタムログインページを持っており、ユーザーが有効になると、私は/ユーザー/テスト/ホームを使用してこのページに彼をリダイレクトしてもhttp://localhost:8086/user/test/home

を使用してみました。しかし、これは働いていなかったのです、私はAllinOne.javaは私のカスタムGenericPortletクラスAllInOne.java:57ある

public void doView(RenderRequest request, RenderResponse response) 
      throws PortletException, IOException { 

     response.setContentType("text/html"); 

     System.out.println("Inside the doView Method"); 
     PortletRequestDispatcher dispatcher = null; 
     if (this.name.isEmpty()) { 
      dispatcher = getPortletContext().getRequestDispatcher(
        "/WEB-INF/jsp/AllInOne_view.jsp"); 
     } else { 
      request.setAttribute("name", this.name); 
      dispatcher = getPortletContext().getRequestDispatcher(
        "http://localhost:8086/user/test/home"); 
     } 
     this.name = ""; 
     this.action = ""; 
     dispatcher.include(request, response); 
    } 


17:53:47,765 ERROR [render_portlet_jsp:154] java.lang.NullPointerException 
    at org.ravi.learning.AllInOne.doView(AllInOne.java:57) 
    at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) 
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) 
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100) 
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64) 
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 

を得ることに保管

dispatcher.include(request, response); 
0123ですパートを更新しました

ここ

これは、私が画像を投稿カント新しいユーザーとして

package org.ravi.learning; 

import java.io.IOException; 

import javax.portlet.ActionRequest; 
import javax.portlet.ActionResponse; 
import javax.portlet.GenericPortlet; 
import javax.portlet.PortletException; 
import javax.portlet.PortletRequestDispatcher; 
import javax.portlet.RenderRequest; 
import javax.portlet.RenderResponse; 

public class AllInOne extends GenericPortlet { 
    String action = ""; 
    String name = ""; 

    public void processAction(ActionRequest request, ActionResponse response) 
      throws PortletException, IOException { 

     System.out.println("Inside the Process Action Method new"); 

     this.action = request.getParameter("myAction"); 

     if (this.action.equals("formAction")) { 
      this.name = request.getParameter("personName"); 

     } 
     String urlpaths = "http://localhost:8086/user/test/home"; 
     response.sendRedirect(urlpaths); 

    } 

    public void doView(RenderRequest request, RenderResponse response) 
      throws PortletException, IOException { 

     response.setContentType("text/html"); 


    } 

} 

ので、画像のために、この外部リンクを参照してください

http://tinypic.com/view.php?pic=a43nlv&s=5

+0

getPortletContext()はオブジェクトを返しますか?ちょうど印刷し、返すものを参照してください –

+0

私は存在するJSPファイルgetPortletContext()。getRequestDispatcherを使用する場合、これは正常に動作しますが、ここで私はデフォルトのランディングページを使用しています。だから、デフォルトのランディングページをこの方法で使用するのが正しいかどうか教えてください。 – Gajjini

+0

@ user1318607何か興味深いものがありますか? – soulcheck

答えて

2

JavaクラスですPortletContext.getRequestDispatcher()のjsr168およびjsr286ドキュメントによれば、

パス名は、スラッシュ(/)で始まり、現在のコンテキストルートからの相対パスとして と解釈されます。

したがって、パラメータとして"http://localhost:8086/user/test/home"を使用すると、間違っています。

あなたがしたいことは、リダイレクトです。ポートレット環境では、アクションリクエストでのみ使用できますActionResponse.sendRedirect(String)

+0

私はActionResponseを使用するので、ここでString値は/ user/test/homeでなければなりません??あれは正しいですか ? – Gajjini

+0

@ user1318607 actionResponseを使用する場合は、http:// localhost:8086/user/test/home'を使用できます。要は、 'doView()'でリダイレクトをしてはならない(できない)ことです。 – soulcheck

+0

私はこの問題で私の質問を更新しました、これを見てください。 – Gajjini

関連する問題