<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="oracle.portal.provider.v2.http.HttpCommonConstants,
                oracle.portal.provider.v2.render.PortletRenderRequest,
                oracle.portal.provider.v2.render.PortletRendererUtil,
                oracle.portal.provider.v2.url.UrlUtils,
                oracle.portal.provider.v2.event.EventUtils,
                oracle.portal.sample.v2.devguide.eventform.EventFormCustomization"
%>

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

    EventFormCustomization defaultData = (EventFormCustomization) 
        PortletRendererUtil.getEditDefaultData(pRequest);

    //
    // The portlet definition in provider.xml includes the following:
    //
    //    The event "submit" with the following event parameters:
    //        o param1
    //        o param2
    //
    //    The event "cancel" with the no event parameters.
    //

    String splashText        = defaultData.getSplashText();
    String parameter1Label   = defaultData.getParameter1Label();
    String parameter2Label   = defaultData.getParameter2Label();
    String submitButtonLabel = defaultData.getSubmitLabel();
    String cancelButtonLabel = defaultData.getCancelLabel();

    String eventSubmit       = EventUtils.eventName("submit");
    String eventSubmitParam1 = EventUtils.eventParameter("param1");
    String eventSubmitParam2 = EventUtils.eventParameter("param2");
    String eventCancel       = EventUtils.eventName("cancel");

 
    // 'disabled' controls whether or not the buttons are disabled.
    boolean disabled        = false;
    String formName         = null;
    String formAction       = null;
    String formHiddenFields = null;
    try
    {
        formName   = UrlUtils.htmlFormName(pRequest,null);
        formAction = UrlUtils.htmlFormActionLink(pRequest, UrlUtils.EVENT_LINK);
        formHiddenFields = 
            UrlUtils.htmlFormHiddenFields(pRequest, UrlUtils.EVENT_LINK);
    }
    catch (IllegalStateException e)
    {
        // This exception is raised if no page reference was available in one
        // of the previous two method calls. 
        // Assume that this happened because the portlet has been added 
        // to a page in a 3.0.9 Portal.
        // Portlet events are only supported for Portal 9.0.2 and later
        // so disable the form.
        disabled = true;
    }
%>

<%=splashText%>

<center>

<!--
  -- Write out the HTML form tag.
  -->
<%
    if (disabled)
    {
        // Display the form with the buttons disabled.
        // The portlet is displayed in a 3.0.9 Portal.
%>
        <form disabled>
<%
    }
    else
    {
        // Display the form with the normal buttons.
%>
        <form name="<%=formName%>" method="POST" action="<%=formAction%>">

        <!--
          -- The values submitted by the form must include hidden special 
          -- form fields that provide system information to the event servlet.
          -->
        <%=formHiddenFields%>
<%
    }
%>


<!--
  -- The following table contains edit fields that will be mapped to
  -- the submit event's parameters when the form is submitted.
  -->
<table>
    <tr>
        <td>
            <b><%=parameter1Label%></b>
        </td>
        <td>
            <input type="text" size="20" name="<%=eventSubmitParam1%>" value="">
        </td>
    </tr>
    <tr>
        <td>
            <b><%=parameter2Label%></b>
        </td>
        <td>
            <input type="text" size="20" name="<%=eventSubmitParam2%>" value="">
        </td>
    </tr>
</table>

<br>

<INPUT TYPE=submit name="<%= eventSubmit %>" Value="<%=submitButtonLabel%>">
<INPUT TYPE=submit name="<%= eventCancel %>" Value="<%=cancelButtonLabel%>">

</form>

</center>

