@Override public void processEvent(EventRequest request, EventResponse response) { _log.info("I m in process event"); Event event = request.getEvent(); if (event.getName().equals("firstName")) { String firstName = (String) event.getValue(); response.setRenderParameter("firstName", firstName); } }
@EventMapping("idPersonne") public void processEventPersonneId(EventRequest eRequest, EventResponse eResponse, Model model) throws PortletException, IOException { Event event = eRequest.getEvent(); int personneId = ((Integer) event.getValue()).intValue(); Personne personne = service.rechercheParId(personneId); if (personne != null) model.addAttribute( "personne", new PersonneViewModel( personne.getId(), personne.getNom(), personne.getPhotoUrl(), personne.getPrenom(), personne.getPrive(), personne.getHomme(), personne.getAnnotations(), false)); }
/** * Save quote from event. * * @param request Request to get event. * @param model Model to return message. */ @EventMapping(SAVE_ACTION) public final void saveQuoteAction(final EventRequest request, final Model model) { final Quote quote = (Quote) request.getEvent().getValue(); getQuoteService().create(quote); model.addAttribute("successMessage", "Quote was saved!"); }
@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING) public void handleSearchEvents(EventRequest request, EventResponse response) { log.debug("Responding to Search Event"); final Event event = request.getEvent(); final SearchRequest searchQuery = (SearchRequest) event.getValue(); final String searchTerms = searchQuery.getSearchTerms(); final SearchResults searchResults = new SearchResults(); searchResults.setQueryId(searchQuery.getQueryId()); searchResults.setWindowId(request.getWindowID()); for (ContactDomain domain : contactDomains) { if (domain.getHasSearch()) { ContactSet contacts = domain.search(searchTerms); for (Contact contact : contacts) { // Build the result object for the match final SearchResult searchResult = new SearchResult(); String title = contact.getSurname().toUpperCase() + ", " + contact.getTitle() + " " + contact.getFirstname(); if (contact.getPosition() != null && !contact.getPosition().equals("")) title += " (" + contact.getPosition() + ")"; List<String> summary = new ArrayList<String>(); ; if (contact.getPrimaryEmailAddress() != null) summary.add("E:" + contact.getPrimaryEmailAddress().getEmailAddress()); if (contact.getPrimaryPhoneNumber() != null) summary.add("T:" + contact.getPrimaryPhoneNumber().getPhoneNumber()); String summaryText = StringUtils.collectionToDelimitedString(summary, " -- "); searchResult.setTitle(title); searchResult.setSummary(summaryText); /* * Portlet URL to be added when / if portlet support for * deep linking added. */ PortletUrl url = new PortletUrl(); url.setPortletMode("VIEW"); url.setWindowState(WindowState.MAXIMIZED.toString()); PortletUrlParameter domainParam = new PortletUrlParameter(); domainParam.setName("domain"); domainParam.getValue().add(domain.getId()); url.getParam().add(domainParam); PortletUrlParameter urnParam = new PortletUrlParameter(); urnParam.setName("urn"); urnParam.getValue().add(contact.getURN()); url.getParam().add(urnParam); searchResult.setPortletUrl(url); searchResult.getType().add("contact"); // Add the result to the results and send the event searchResults.getSearchResult().add(searchResult); } } } response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, searchResults); log.debug( "Finished response -- " + searchResults.getSearchResult().size() + " -- results returned"); }
public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException { logger.debug(Logger.SEPARATOR); logger.debug("execute(EventRequest, EventResponse) portletName=[{0}]", portletName); try { // If there is a bridgeEventHandler registered in portlet.xml, then String bridgeEventHandlerAttributeName = Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_EVENT_HANDLER; BridgeEventHandler bridgeEventHandler = (BridgeEventHandler) portletContext.getAttribute(bridgeEventHandlerAttributeName); init(eventRequest, eventResponse, Bridge.PortletPhase.EVENT_PHASE); if (bridgeEventHandler != null) { // Restore the BridgeRequestScope that may have started during the ACTION_PHASE. bridgeRequestScope.restoreState(facesContext); // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202 bridgeRequestScope.setPortletMode(eventRequest.getPortletMode()); // Execute the JSF lifecycle so that ONLY the RESTORE_VIEW phase executes (note that this // this is // accomplished by the IPCPhaseListener). facesLifecycle.execute(facesContext); // If there were any "handled" exceptions queued, then throw a BridgeException. Throwable handledException = getJSF2HandledException(facesContext); if (handledException != null) { throw new BridgeException(handledException); } // Otherwise, if there were any "unhandled" exceptions queued, then throw a BridgeException. Throwable unhandledException = getJSF2UnhandledException(facesContext); if (unhandledException != null) { throw new BridgeException(unhandledException); } // Set a flag on the bridge request scope indicating that the Faces Lifecycle has executed. bridgeRequestScope.setFacesLifecycleExecuted(true); // If there is a bridgeEventHandler registered in portlet.xml, then invoke the handler so // that it // can process the event payload. logger.debug( "Invoking {0} for class=[{1}]", bridgeEventHandlerAttributeName, bridgeEventHandler.getClass()); Event event = eventRequest.getEvent(); EventNavigationResult eventNavigationResult = bridgeEventHandler.handleEvent(facesContext, event); if (eventNavigationResult != null) { String oldViewId = facesContext.getViewRoot().getViewId(); String fromAction = eventNavigationResult.getFromAction(); String outcome = eventNavigationResult.getOutcome(); logger.debug( "Invoking navigationHandler fromAction=[{0}] outcome=[{1}]", fromAction, outcome); NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler(); navigationHandler.handleNavigation(facesContext, fromAction, outcome); String newViewId = facesContext.getViewRoot().getViewId(); bridgeRequestScope.setNavigationOccurred(!oldViewId.equals(newViewId)); } // Save the faces view root and any messages in the faces context so that they can be // restored during // the RENDER_PHASE of the portlet lifecycle. bridgeRequestScope.saveState(facesContext); // Assume that the bridge request scope should be maintained from the EVENT_PHASE into the // RENDER_PHASE by utilizing render parameters. BridgeRequestScope.Transport bridgeRequestScopeTransport = BridgeRequestScope.Transport.RENDER_PARAMETER; Serializable eventPayload = event.getValue(); // FACES-1465: If the portlet developer intentionally wrapped the event payload is with an // EventPayloadWrapper, then determine whether or not this is happening during a redirect. // If this is // the case, then the bridge request scope must be maintained from the EVENT_PHASE into the // RENDER_PHASE // by utilizing a portlet session attribute. This is because render parameters will not // survive a // redirect. if ((eventPayload != null) && (eventPayload instanceof EventPayloadWrapper)) { EventPayloadWrapper eventPayloadWrapper = (EventPayloadWrapper) eventPayload; if (eventPayloadWrapper.isRedirect()) { bridgeRequestScopeTransport = BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE; } } maintainBridgeRequestScope(eventRequest, eventResponse, bridgeRequestScopeTransport); // Process the outgoing public render parameters. // TCK TestPage064: eventControllerTest processOutgoingPublicRenderParameters(facesLifecycle); } // Maintain the render parameters set in the ACTION_PHASE so that they carry over to the // RENDER_PHASE. bridgeContext.getPortletContainer().maintainRenderParameters(eventRequest, eventResponse); // Spec 6.6 (Namespacing) indicateNamespacingToConsumers(facesContext.getViewRoot(), eventResponse); } catch (Throwable t) { throw new BridgeException(t); } finally { cleanup(); } }
@EventMapping(value = "event.risultatiRicerca") public void effettuaRicerca(EventRequest request, EventResponse response) { RicercaLiberaDTO ricercaDTO = (RicercaLiberaDTO) request.getEvent().getValue(); response.setRenderParameter("action", ricercaDTO.getTipoRicerca()); response.setRenderParameter("cercaPerKeyword", ricercaDTO.getCercaPerKeyword()); }
public void processEvent(EventRequest request, EventResponse response) { Event event = request.getEvent(); String event_name = event.getName(); // System.out.println("[PortletWebBrowser.processEvent] event : " + event.getName()); if (event_name.equals("tohighlight")) { Object _highlight_event = event.getValue(); // Récupérer la collection de highlights if (_highlight_event instanceof HighlightSelectionHTML) { ArrayList<HighlightSelectionHTML> _hightlights = (ArrayList<HighlightSelectionHTML>) request.getPortletSession().getAttribute("highlights"); if (_hightlights == null) _hightlights = new ArrayList<HighlightSelectionHTML>(); _hightlights.add((HighlightSelectionHTML) _highlight_event); request.getPortletSession().setAttribute("highlights", _hightlights); } } if (event_name.equals("todelete")) { // System.out.println("[PortletWebBrowser.processEvent] event to delete"); if (event.getValue() instanceof HighlightSelectionHTML) doDelete(request, (HighlightSelectionHTML) event.getValue()); } if (event_name.equals("toLoadUrl")) { if (event.getValue() instanceof String) { String url = (String) event.getValue(); if (url.startsWith("http://")) { request.getPortletSession().setAttribute("current_url", url); // response.setRenderParameter("url", url.toLowerCase()); request.getPortletSession().removeAttribute("highlights"); request.removeAttribute("highlights"); // gestion de la consultation if (request.getPortletSession().getAttribute("consult_url") != null) // si une consultation a déjà commencé { if (!url.equalsIgnoreCase( (String) request .getPortletSession() .getAttribute("consult_url"))) // si on change de page à consulter { if (request.getPortletSession().getAttribute("user") != null) { // creates consultation // URI uri = // CREATOR_URI.createAndGetURI((String)request.getPortletSession().getAttribute("consult_url")); // CREATOR_CONSULTATION.createsConsultation((UserAccount)request.getPortletSession().getAttribute("user"), (Date)request.getPortletSession().getAttribute("start_consult") , new Date(), uri, "[PortletWebBrowse]"); URI uri = daoResource.createAndGetURI( (String) request.getPortletSession().getAttribute("consult_url")); daoConsultation.createsConsultation( (UserAccount) request.getPortletSession().getAttribute("user"), (Date) request.getPortletSession().getAttribute("start_consult"), new Date(), uri, "[PortletWebBrowse]"); } request.getPortletSession().setAttribute("consult_url", url); request.getPortletSession().setAttribute("start_consult", new Date()); } } else // si c'est la première consultation { request.getPortletSession().setAttribute("consult_url", url); request.getPortletSession().setAttribute("start_consult", new Date()); } } } } if (event_name.equalsIgnoreCase("UserLog")) { if (event.getValue() instanceof UserAccount) { UserAccount _current_user = (UserAccount) event.getValue(); if (_current_user.getId() != null) request.getPortletSession().setAttribute("user", _current_user); } } if (event_name.equalsIgnoreCase("UserUnLog")) { request.getPortletSession().removeAttribute("user"); } }