<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*, oracle.portal.provider.v2.*" %>
<%@page import="oracle.portal.provider.v2.http.HttpCommonConstants" %>
<%@page import="oracle.portal.provider.v2.render.PortletRendererUtil" %>
<%@page import="oracle.portal.provider.v2.render.PortletRenderRequest" %>
<%@page import="oracle.portal.provider.v2.render.http.HttpPortletRendererUtil" %>
<%@page import="oracle.portal.provider.v2.url.UrlUtils" %>

<%

    // The form submit URL refers to the current Portal page.  All portlets
    // on this page share this URL.  This means that the per portlet parameters
    // are in the same request.  Portlets must ensure that its paramerters don't
    // collide either with other portlets or other instances of itself.  This
    // is generally accomplished by using "fully-qualified" parameter names. A
    // fully-qualified parameter name prepends the (unique) portlet reference to
    // the parameter.  The JPDK provides a utility to accomplish this.

    String portletParamName    = "mName";
    String portletParamAge     = "mAge";
    String portletParamSubmit  = "mSubmit";
    String fName = HttpPortletRendererUtil.portletParameter(request, portletParamName);
    String fAge  = HttpPortletRendererUtil.portletParameter(request, portletParamAge);
    String fSubmit = HttpPortletRendererUtil.portletParameter(request, portletParamSubmit);

    // These are the session attribute names used to store the current values.
    // Because all instances of this portlet share the same user session we must
    // also fully-qualify these names to avoid collisions.

    String sName = HttpPortletRendererUtil.portletParameter(request, "sName");
    String sAge  = HttpPortletRendererUtil.portletParameter(request, "sAge");



    PortletRenderRequest pRequest = (PortletRenderRequest)
        request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

    String formName = UrlUtils.htmlFormName(pRequest,null);
    ProviderUser user = pRequest.getUser();
    ProviderSession providerSession = user.getSession();
    if (providerSession == null)
    {
%>
        Your provider session has been terminated or has timed out
        and you need to logout and then login to re-establish the session.
<%
    }
    else
    {
        // Record, in session storage, the last values submitted.
        if (pRequest.getQualifiedParameter(portletParamSubmit) != null)
        {
           providerSession.setAttribute(sName, pRequest.getQualifiedParameter(portletParamName));
           providerSession.setAttribute(sAge,  pRequest.getQualifiedParameter(portletParamAge));
        }
%>

<!-- Output the HTML content -->

<center>

<table width="70%">
  <tr>
     <td>
         <b>This portlet shows how to post and process information from HTML forms.</b>
     </td>
  </tr>
</table>

<form name="<%= formName %>" method="POST" 
   action="<%= UrlUtils.htmlFormActionLink(pRequest,UrlUtils.PAGE_LINK) %>"> 
 
<%= UrlUtils.htmlFormHiddenFields(pRequest,UrlUtils.PAGE_LINK, formName) %> 

<table>
   <tr>
      <td>
         <b>Name :</b>
      </td>
      <td>
         <input type="text" size="20" name="<%= fName %>" value="">
      </td>
   </tr>
   <tr>
      <td>
         <b>Age : </b>
      </td>
      <td>
         <input type="text" size="3" name="<%= fAge %>" value="">
      </td>
   </tr>
</table>

<br>

<INPUT TYPE=submit name="<%= fSubmit %>" Value="Submit">

</form>

<%
if ((providerSession.getAttribute(sName) == null)&& (providerSession.getAttribute(sAge) == null)) {
%>
   <b>No values have been submitted yet.</b>
<%
} else {
%>
   <b> Last submitted values:</b><br>

   <table>
      <tr>
         <td>
            <b>Name: </b>
         </td>
         <td>
            <b><%= providerSession.getAttribute(sName) %></b>
         </td>
      </tr>
      <tr>
         <td>
            <b>Age: </b>
         </td>
         <td>
            <b><%= providerSession.getAttribute(sAge) %></b>
         </td>
      </tr>
   </table>
<%
}
%>

</center>
<%
    }
%>
<!-- End output the HTML content -->
