public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, CommunicationException, NamingException
{
String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
EmailFacadeHome cfh = (EmailFacadeHome)CVUtility.getHomeObject("com.centraview.email.emailfacade.EmailFacadeHome", "EmailFacade");
try
{
DynaActionForm dynaForm = (DynaActionForm)form;
HttpSession session = request.getSession(true);
UserObject userobjectd = (UserObject)session.getAttribute("userobject");
int individualID = userobjectd.getIndividualID();
ListPreference listpreference = userobjectd.getListPreference("Email");
String rowId = null;
rowId = request.getParameter("rowId");
int messageID = Integer.parseInt(rowId);
String listAction = request.getParameter("listAction");
String folderid = request.getParameter("folderid");
if (folderid == null)
{
folderid = (String)session.getAttribute("folderid");
}
else
{
session.setAttribute("folderid", folderid);
}
String indexfrompage = request.getParameter("index");
System.out.println("indexfrompage"+indexfrompage);
if (listAction != null && listAction.equals("next"))
{
System.out.println("messageID"+messageID);
messageID = messageID - 1 ;
int index = 0;
if (indexfrompage != null){
index = Integer.parseInt(indexfrompage);
indexfrompage = (index - 1)+"";
}
rowId = messageID + "";
}
System.out.println("indexfrompage"+indexfrompage);
DisplayList displaylistSession = (DisplayList)session.getAttribute("displaylist");
int index = 0;
boolean flag = false;
// THIS IS UTTER SILLINESS. WHY ARE WE LOOPING THROUGH A SESSION ATTRIBUTE
// WITH A GENERIC NAME LIKE "displaylist", WHICH COULD HAVE BEEN SET
// BY *ANY* HANDLER, WHEN WE *ALREADY HAVE* THE KEY TO THE MESSAGE?!??!
// I'VE INTRODUCED A HACK HERE, TO ACCOUNT FOR CASES IN WHICH WE'RE TRYING
// TO VIEW A MESSAGE DETAILS, BUT WE HAVEN'T COME FROM THE EMAIL LIST SCREEN.
if (displaylistSession != null && (displaylistSession.getListType()).equals("Email"))
{
Set listkey = displaylistSession.keySet();
Iterator it = listkey.iterator();
while (it.hasNext())
{
index++;
String str = (String)it.next();
ListElement ele = (ListElement)displaylistSession.get(str);
ListElementMember sm = (ListElementMember)ele.get("MessageID");
Integer id = (Integer)sm.getMemberValue();
int messageid = id.intValue();
if (index == (Integer.parseInt(indexfrompage)))
{
flag = true;
messageID = messageid;
break;
}
} // end while(it.hasNext())
}
else
{
flag = true;
}
/*
if (listAction != null && listAction.equals("next"))
{
System.out.println("messageID"+messageID);
messageID = messageID - 1 ;
rowId = messageID + "";
}
*/
System.out.println("messageID after"+messageID);
if (indexfrompage != null)
{
dynaForm.set("index", indexfrompage);
}
else
{
dynaForm.set("index", Integer.toString(index));
}
if (flag == true)
{
MailMessage mailmessage = null;
EmailFacade remote = (EmailFacade)cfh.create();
HashMap hm = new HashMap();
hm.put("MessageID", new Integer(messageID));
mailmessage = remote.getMailMessage(individualID, hm);
remote.setDataSource(dataSource);