<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.text.DateFormat, java.util.Date, java.util.List,
  java.util.Iterator, oracle.portal.provider.v2.render.PortletRenderRequest,
  oracle.portal.provider.v2.render.PortletRendererUtil,
  oracle.portal.provider.v2.render.PortletRenderer,
  oracle.portal.provider.v2.url.UrlUtils,
  oracle.portal.provider.v2.preference.Preference,
  oracle.portal.provider.v2.preference.NameValuePreferenceDataObject,
  oracle.portal.provider.v2.http.HttpCommonConstants,
  oracle.portal.sample.v2.devguide.prefstore.GuestBookPortletDefinition" %>
<%!
private static final String SUBMIT_PARAM = "submit";
private static final String VISITOR_NAME_KEY = "name";
private static final String DATE_KEY = "date";
private static final String COMMENT_KEY = "comment";
%>
<%
PortletRenderRequest prr = (PortletRenderRequest)
    request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

if(prr == null)
{%>
This JSP will not run outside of Oracle Portal.
<%
  return;
}

GuestBookPortletDefinition gbpd = 
     (GuestBookPortletDefinition)prr.getPortletDefinition();

%>
<form method="post" name="<%= UrlUtils.htmlFormName(prr,null) %>"
  action="<%= UrlUtils.htmlFormActionLink(prr, UrlUtils.DESIGN_LINK) %>">

<%= UrlUtils.htmlFormHiddenFields(prr, UrlUtils.DESIGN_LINK) %>
<%= 
  // add parameters to send the output of the form to the EDIT page
  UrlUtils.emitHiddenField("_mode", 
                           Integer.toString(PortletRenderer.MODE_EDIT)) 
%>


  <table cellpadding="2" cellspacing="2" border="1">
    <tbody>
      <tr>
        <th valign="Top">User Name<br>
        </th>
        <th valign="Top">Date Visited<br>
        </th>
        <th valign="Top">Comments<br>
        </th>
      </tr>
<%
  List entries = gbpd.getGuestBookEntries(prr.getProviderInstance());
  for(Iterator i = entries.iterator(); i.hasNext();)
  {
    Preference pref = (Preference)i.next();
    NameValuePreferenceDataObject data = 
      (NameValuePreferenceDataObject)pref.getData();      
%>
      <tr>
        <td valign="Top"><%=data.getString(VISITOR_NAME_KEY)%><br>
        </td>
        <td valign="Top"><%=data.getString(DATE_KEY)%><br>
        </td>
        <td valign="Top"><%=data.getString(COMMENT_KEY)%></td>
      </tr>
<%
  }
  String commentName = PortletRendererUtil.portletParameter(prr, COMMENT_KEY);
  String submitName = PortletRendererUtil.portletParameter(prr, SUBMIT_PARAM);
%>
      <tr>
        <td colspan="3">
          Please enter your comment here:<br>
          <textarea name="<%= commentName %>" rows="5" cols="40">
            No comment.
          </textarea>
          <input type="submit" name="<%= submitName %>" value="Send" />
          <input type="reset" value="Reset" />
        </td>
      </tr>
    </tbody>
  </table>
</form>
