<%@ page session="false" contentType="text/html;charset=UTF-8" %> 
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="oracle.portal.provider.v2.http.HttpCommonConstants" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRenderRequest" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRendererUtil" %>
<%@ page import="oracle.portal.sample.v2.devguide.eventform.EventFormCustomization" %>
<%@ page import="oracle.portal.sample.v2.devguide.eventform.resource.EventFormBundle" %>

<%
    //
    // This JSP both displays the customization form and processes it.
    //

    //
    // Get the portlet render request object.
    //
    PortletRenderRequest prr = (PortletRenderRequest)
        request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

    //
    // Get the customization data.
    //
    EventFormCustomization data = 
        (EventFormCustomization)PortletRendererUtil.getEditData(prr);

    //
    // This JSP can be rendered either as the result of 
    //
    //   1) clicking a customization link from show MODE
    //   2) clicking the OK or APPLY button after this JSP was previously 
    //      rendered, i.e. submitting the customization data
    //      (Note that clicking CANCEL automitically redirects to show MODE.)
    //
    // If the edit form parameter has a value then the customization data
    // is being submitted.
    //
    String actionParam = PortletRendererUtil.getEditFormParameter(prr);
        String action = request.getParameter(actionParam);
    if (action != null)
    {
        //
        // The customization data is being submitted.
        // Get the customization values that were passed as parameters 
        // save them into the customization store.
        //
        String title = request.getParameter("eventform_title");
        String shortTitle = request.getParameter("eventform_short_title");

        data.setPortletTitle(title);
        data.setPortletShortTitle(shortTitle);

        //
        // Since the EventFormCustomization object can be used to hold
        // customizations and default data remove the default data initial
        // settings to save storage space.
        //
        data.removeEditDefaultData();

        //
        // Submit the customizations.
        //
        PortletRendererUtil.submitEditData(prr, data);
        return;
    }

    //
    // The customization data is not being submitted.
    // Display the customization form that will allow the user to change
    // and submit the customization values.
    //

    //
    // Get the labels for the various edit fields.
    //
    Locale locale = prr.getPortletReference().getLocale();
    ResourceBundle bundle = 
        prr.getPortletDefinition().getResourceBundle(locale);

    String titleLabel = bundle.getString(EventFormBundle.TITLE_LABEL_KEY);
    String shortTitleLabel = 
            bundle.getString(EventFormBundle.SHORTTITLE_LABEL_KEY);

    //
    // Get the initial values for the various edit fields.
    //
    String title           = data.getPortletTitle();
    String shortTitle      = data.getPortletShortTitle();
%>

<TABLE BORDER="0">
  <TR>
    <TD WIDTH="40%">
            <P ALIGN="RIGHT"><%=titleLabel%>
    </TD>
    <TD WIDTH="80%">
      <INPUT TYPE="TEXT" NAME="eventform_title" VALUE="<%= title %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=shortTitleLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_short_title" VALUE="<%= shortTitle %>" SIZE="30">
    </TD>
  </TR>
</TABLE>

