<%-- 
/**
  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  * USA
  *
  * Component of: Red Hat Application Server
  * 
  * Initial Developers: Aizaz Ahmed
  *                     Vivek Lakshmanan
  *                     Andrew Overholt
  *                     Matthew Wringe
  *
  */
--%>

<%-- This page provides a detailed view for Items. It expects the item
object ItemLocal to be defined as itemToDisplay. This is clumsy ... if necessary
it should be modified so that the item is loaded into the session and the
name of the item is passed to this page --%>

<%@ page contentType="text/html"
         import="olstore.entity.*"
	 	 import="olstore.framework.EJBHomeFactory"
         import="java.util.Collection"
         import="java.util.Iterator" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>

<%
    EJBHomeFactory factory = EJBHomeFactory.getInstance();
    ItemLocal item = (ItemLocal) request.getAttribute( "itemToDisplay" );
    String username = request.getRemoteUser ();
    if ( username != null ) {
        UserLocalHome userHome = (UserLocalHome) factory.getLocalHome (EJBHomeFactory.USER);
        Collection users = userHome.findByFriendsOfPurchased ( username, item );

        Iterator it = users.iterator();
        if ( ! users.isEmpty() ) {
%>
            <p class="desc" style="font-style:italic">Purchased / Marked as Interesting by:
<%
        }

        while ( it.hasNext () ) {
            UserLocal friend = (UserLocal) it.next();
	    pageContext.setAttribute ("friendStrut",friend, PageContext.REQUEST_SCOPE);
%>
            <html:link href="<%="mailto:"+friend.getEmailAdd()%>"><%=friend.getFname()%> <%=friend.getLname()%></html:link><%=it.hasNext()?",":""%>
<%
        }
    }

%>      
    </p>
