2015-11-13 1 views
0

Ceci est ma première question sur ce site. S'il vous plaît ignorer mon erreur grammaticale anglaise.Comment afficher le message de réussite dans liferay sans utiliser de session?

J'essaye d'afficher le succès et le message d'erreur dans liferay sans utiliser la session après avoir soumis la réponse dans la page.

J'utilise liferay6.2CE

Mon contrôleur est ci-dessous.

TestController

import java.io.IOException; 
import java.util.ArrayList; 
import java.util.List; 

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

import com.liferay.portal.kernel.util.ParamUtil; 
import com.liferay.util.bridges.mvc.MVCPortlet; 
import com.techm.test1.service.Service; 
public class TestController extends MVCPortlet{ 
    protected void include(String path,RenderRequest renderRequest,RenderResponse renderResponse) throws IOException, PortletException{ // include methos starts here 
     PortletRequestDispatcher reqDispatcher = getPortletContext().getRequestDispatcher(path); 
     if(reqDispatcher!=null) { 
      reqDispatcher.include(renderRequest, renderResponse); 
     } 
    } 
    public void processAction(ActionRequest actionRequest,ActionResponse actionResponse) throws IOException, PortletException 
    { 

     String userId = actionRequest.getRemoteUser(); 

     Service s=new Service(); 
     List outputList=new ArrayList(); 

     String Question1 = ParamUtil.getString(actionRequest, "Question1"); 
     outputList.add(Question1); 

     String Question2 = ParamUtil.getString(actionRequest, "Question2"); 
     outputList.add(Question2); 

     String Question3 = ParamUtil.getString(actionRequest, "Question3"); 
     outputList.add(Question3); 
outputList.add(ParamUtil.getString(actionRequest, "Question15")); 
     //outputList.add(Question15); 

     Boolean bl=s.getoutputList(outputList,userId); 
} 
} 

view.jsp

<%@page import="com.techm.test1.model.Model"%> 
<%@page import="java.util.List"%> 

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> 

<portlet:defineObjects /> 


This is the 
<b>Test !!</b> 
portlet. 
<div> 

    <portlet:actionURL var="submitFormURL"></portlet:actionURL> 
    <form method="POST" action=<%=submitFormURL%>> 
     1.Predict the output of following Java program 
     <pre class="brush:java"> 
class Main { 
    public static void main(String args[]) { 
     try { 
      throw 10; 
     } 
     catch(int e) { 
      System.out.println("Got the Exception " + e); 
     } 
    } 
} 

<br /> 
     </pre> 
     <input type="radio" value="Got Exception 10" 
      name="<portlet:namespace/>Question1" />Got Exception 10</br> <input 
      type="radio" value="Got Exception 0" 
      name="<portlet:namespace/>Question1" />Got Exception 0</br> <input 
      type="radio" value="Compiler Error" 
      name="<portlet:namespace/>Question1" />Compiler Error</br> </br>2. Which of 
     the following is true about inheritance in Java? <br /> 
     <pre class="brush:java"> 
1) Private methods are final. 
2) Protected members are accessible within a package and 
    Inherited classes outside the package. 
3) Protected methods are final. 
4) We cannot override private methods. 
<br /> 

     </pre> 
     <input type="radio" value="1" name="<portlet:namespace/>Question2" />1</br> 
     <input type="radio" value="Only 1 2" 
      name="<portlet:namespace/>Question2" />Only 1, 2</br> <input type="radio" 
      value="1,2 and 3" name="<portlet:namespace/>Question2" />1,2, 3</br></br> 
     3.Output of follwoing Java program<br /> 
     <pre class="brush:java"> 
class Main { 
    public static void main(String args[]) { 
     final int i; 
     i = 20; 
     System.out.println(i); 
    } 
} 
<br /> 
     </pre> 
     <input type="radio" value="1" name="<portlet:namespace/>Question3" />1</br> 
     <input type="radio" value="Only 1 2" 
      name="<portlet:namespace/>Question3" />Only 1, 2</br> <input type="radio" 
      value="1,2 and 3" name="<portlet:namespace/>Question3" />1,2, 3</br></br> 

     <input type="submit" id="submit" value="Submit"> 

    </form> 
</div> 

Comment faire?

Toute aide ..

+0

Utiliser session est la bonne façon. Pourquoi ne veux-tu pas l'utiliser? –

+0

Oui, pourquoi ne pas utiliser les sessions? Il vous conduit à un certain nombre d'avantages ... et le coût de calcul ne cesse d'augmenter qu'une solution basée sur demande seulement ... –

+0

Nous vous remercions de vos suggestions. – Ismail

Répondre

0

Je l'ai

Dans méthode processAction i utilisé ci-dessous le code.

Boolean bl=s.getoutputList(outputList,userId); 

     if(!bl){ 
      actionResponse.setRenderParameter("Result", TestDetailsConstants.TEST_ERROR_MSG); 
     } 
     else{ 
      actionResponse.setRenderParameter("Result",TestDetailsConstants.TEST_SUCCESS_MSG); 
     } 

J'appelle cela dans méthode doView et passer msg à jsp et l'affichage

public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException 
    { 
     String viewPage=""; 
     String s=""; 
     try 
     { 

     viewPage = "/view.jsp"; 
     s=renderRequest.getParameter("Result"); 

     renderRequest.setAttribute("Strimgmesg",s); 
     }// try block ends here 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     }// catch block ends here 

     finally { 

      include(viewPage,renderRequest,renderResponse); 
     } 
    } 

Dans JSP

</br> <input type="submit" id="submit" value="Submit"> 
     <% 
      String a = (String) renderRequest.getAttribute("Strimgmesg"); 
     %> 
     <% 
      if (a != null) { 
     %> 
     <%=a%> 
     <% 
      } 
     %>