portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/demo/simple PickANumber.jsp
Date Mon, 29 Mar 2004 04:48:40 GMT
taylor      2004/03/28 20:48:40

  Modified:    applications/demo/src/java/org/apache/jetspeed/demo/simple
                        PickANumberServlet.java
               applications/demo/src/webapp/WEB-INF portlet.xml
               applications/demo/src/webapp/WEB-INF/demo/simple
                        PickANumber.jsp
  Log:
  Updated Pick A Number portlet to show how to use post parameters in a portlet
  NOTE: This portlet is broken due to JIRA bug JS2-2
  
  Revision  Changes    Path
  1.4       +18 -12    jakarta-jetspeed-2/applications/demo/src/java/org/apache/jetspeed/demo/simple/PickANumberServlet.java
  
  Index: PickANumberServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/demo/src/java/org/apache/jetspeed/demo/simple/PickANumberServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PickANumberServlet.java	25 Mar 2004 21:41:46 -0000	1.3
  +++ PickANumberServlet.java	29 Mar 2004 04:48:39 -0000	1.4
  @@ -16,9 +16,10 @@
   package org.apache.jetspeed.demo.simple;
   
   import java.io.IOException;
  +
  +import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
   import javax.portlet.PortletException;
  -import javax.portlet.PortletRequest;
   import javax.portlet.PortletSession;
   import org.apache.jetspeed.portlet.ServletPortlet;
   
  @@ -103,10 +104,10 @@
       /**
        * Increment attributes in different scopes
        *
  -     * @see javax.portlet.GenericPortlet#processAction
  +     * @see javax.portlet.GenericPortlet#processActions
        *
        */
  -    public void processAction(PortletRequest request, ActionResponse actionResponse)
  +    public void processAction(ActionRequest request, ActionResponse actionResponse)
       throws PortletException, IOException
       {
           Long guessCount = null;
  @@ -117,10 +118,10 @@
           PortletSession session = request.getPortletSession();
           
           // Get target value
  -        lastGuess = (Long)session.getAttribute(LAST_GUESS_NAME, PortletSession.PORTLET_SCOPE);
  +        lastGuess = (Long)session.getAttribute(LAST_GUESS_NAME, PortletSession.APPLICATION_SCOPE);
   
           // Get target value
  -        targetValue = (Long)session.getAttribute(TARGET_VALUE_NAME, PortletSession.PORTLET_SCOPE);
  +        targetValue = (Long)session.getAttribute(TARGET_VALUE_NAME, PortletSession.APPLICATION_SCOPE);
           if ((targetValue != null) && (lastGuess != null))
           {
               if (targetValue.equals(lastGuess))
  @@ -130,13 +131,13 @@
           {
               targetValue = new Long(Math.round(Math.random() * 10.0));
               guessCount = new Long(0);
  -            session.setAttribute( TARGET_VALUE_NAME, targetValue, PortletSession.PORTLET_SCOPE);
  +            session.setAttribute( TARGET_VALUE_NAME, targetValue, PortletSession.APPLICATION_SCOPE);
           }
   
           // Get the guessCount, if it has not already been set.
           if (guessCount == null)
           {
  -            guessCount = (Long)session.getAttribute(GUESS_COUNT_NAME, PortletSession.PORTLET_SCOPE);
  +            guessCount = (Long)session.getAttribute(GUESS_COUNT_NAME, PortletSession.APPLICATION_SCOPE);
               if (guessCount == null)
               {
                   guessCount = new Long(0);
  @@ -149,7 +150,12 @@
           
           try
           {
  -            currentGuess = new Long(request.getParameter(GUESS_PARAMETER_NAME));
  +            String result = request.getParameter(GUESS_PARAMETER_NAME);
  +            // System.out.println("result = " + result);
  +            if (result != null)
  +            {
  +                currentGuess = new Long(result);
  +            }
           }
           catch (Exception e)
           {
  @@ -157,9 +163,9 @@
           }
   
           // Update the attribute values
  -        session.setAttribute( GUESS_COUNT_NAME, guessCount, PortletSession.PORTLET_SCOPE);
  -        session.setAttribute( LAST_GUESS_NAME, currentGuess, PortletSession.PORTLET_SCOPE);
  -        
  +        session.setAttribute( GUESS_COUNT_NAME, guessCount, PortletSession.APPLICATION_SCOPE);
  +        session.setAttribute( LAST_GUESS_NAME, currentGuess, PortletSession.APPLICATION_SCOPE);
  +        actionResponse.setProperty(LAST_GUESS_NAME, currentGuess.toString());
           return;
       }
   }
  
  
  
  1.8       +8 -0      jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/portlet.xml
  
  Index: portlet.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/portlet.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- portlet.xml	18 Mar 2004 19:35:09 -0000	1.7
  +++ portlet.xml	29 Mar 2004 04:48:40 -0000	1.8
  @@ -104,6 +104,14 @@
     </portlet>
   
     <portlet id="PickANumberPortlet">
  +    <init-param>
  +      <name>ViewPage</name>
  +      <value>/WEB-INF/demo/simple/PickANumber.jsp</value>
  +    </init-param>    
  +    <init-param>
  +      <name>HelpPage</name>
  +      <value>/WEB-INF/demo/simple/PickANumberHelp.jsp</value>
  +    </init-param>          
       <portlet-name>PickANumberPortlet</portlet-name>
       <display-name>Pick a number game</display-name>
       <portlet-class>org.apache.jetspeed.demo.simple.PickANumberServlet</portlet-class>
  
  
  
  1.3       +35 -5     jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/demo/simple/PickANumber.jsp
  
  Index: PickANumber.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/demo/simple/PickANumber.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PickANumber.jsp	18 Mar 2004 19:35:02 -0000	1.2
  +++ PickANumber.jsp	29 Mar 2004 04:48:40 -0000	1.3
  @@ -15,24 +15,54 @@
   --%>
   <%@ page language="java" session="true" %>
   <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
  +<%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
  +<%@ page import="javax.portlet.PortletSession"%>
  +<portlet:defineObjects/>
  +
  +<portlet:actionURL var="myAction">
  +	<portlet:param name="myParam" value="testParam"/>
  +</portlet:actionURL>
   
   <c:if test="${empty targetValue}">
     <c:set var="targetValue" scope="session" value="5"/>
     <c:set var="guessCount" scope="session" value="0"/>
   </c:if>
   
  +<%
  +    PortletSession portletSession = renderRequest.getPortletSession();
  +    Long lg = (Long)portletSession.getAttribute("LastGuess", PortletSession.APPLICATION_SCOPE);
  +    String lastGuess = "50";
  +    if (lg != null)
  +    {
  +    	lastGuess = lg.toString();
  +    }
  +    else
  +    {
  +    	lg = new Long(50);
  +    	lastGuess = "50";
  +    }    	
  +%>
  +
   <c:set var="guessCount" scope="session" value="${guessCount + 1}"/>
  +
  +target =  <c:out value="${targetValue}"/>
  +<br/>
  +
  +last guess =  <c:out value="${param.Guess}"/>
  +
  +<br/>
  +
   <div>
  -  You guessed <c:out value="${param.Guess}"/>
  +  You guessed <%=lastGuess%>
     <br/>
     Guess Count <c:out value="${guessCount}"/>
     <br/>
     <c:choose>
  -    <c:when test="${targetValue == param.Guess}">
  +    <c:when test="${targetValue == (param.Guess + 0)}">
         <center><strong>You have guessed the number!!!!</strong></center>
         <c:remove var="targetValue" scope="session"/> 
       </c:when>
  -    <c:when test="${targetValue < (param.Guess + 0) }">
  +    <c:when test="${targetValue < (param.Guess + 0)}">
         You have guessed to high.  Try a lower Number
       </c:when>
       <c:when test="${targetValue > (param.Guess + 0)}">
  @@ -40,8 +70,8 @@
       </c:when>
     </c:choose>
     <br/>
  -  <form action="PickANumber.jsp" method="POST">
  -    <input type="text" name="Guess">
  +  <form action="<%=myAction%>" method="POST">
  +    <input type="text" name="Guess" value="<%=lastGuess%>">
       <input type="submit">
     </form>
   </div>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message