int individualID = userObject.getIndividualID(); // logged in user
int entityID = userObject.getEntityId(); // entityID of the logged-in user's entity
ActionErrors allErrors = new ActionErrors();
try {
ListPreference listPreference = userObject.getListPreference("Email");
ValueListParameters listParameters = ActionUtil.valueListParametersSetUp(listPreference, request, ValueListConstants.CUSTOMER_EMAIL_LIST_TYPE, ValueListConstants.customerEmailViewMap, false);
String filter = "SELECT em.MessageID " +
"FROM emailmessage em LEFT JOIN emailrecipient er ON (em.MessageID=er.MessageID) " +
"LEFT JOIN emailmessagefolder es ON (em.MessageID = es.MessageID) " +
"LEFT JOIN methodofcontact moc ON (er.Address=moc.Content) " +
"LEFT JOIN mocrelate mr ON (moc.MOCID=mr.MOCID) " +
"LEFT JOIN individual i ON (mr.ContactID=i.IndividualID) " +
"WHERE mr.ContactType=2 AND moc.MOCType=1 AND es.FolderID IS NOT NULL AND i.Entity = " + entityID +
" UNION SELECT em.MessageID " +
"FROM emailmessage em LEFT JOIN emailrecipient er ON (em.MessageID=er.MessageID) " +
"LEFT JOIN emailmessagefolder es ON (em.MessageID = es.MessageID) " +
"LEFT JOIN methodofcontact moc ON (er.Address=moc.Content) " +
"LEFT JOIN mocrelate mr ON (moc.MOCID=mr.MOCID) " +
"WHERE mr.ContactType=1 AND moc.MOCType=1 AND es.FolderID IS NOT NULL AND mr.ContactID = " + entityID;
listParameters.setFilter(filter);
ValueList valueList = (ValueList)CVUtility.setupEJB("ValueList", "com.centraview.valuelist.ValueListHome", dataSource);
ValueListVO listObject = valueList.getValueList(individualID, listParameters);
ValueListDisplay displayParameters = new ValueListDisplay(new ArrayList(), false, false, true, true, true, true);
listObject.setDisplay(displayParameters);
request.setAttribute("valueList", listObject);