public void login() {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext externalContext = context.getExternalContext();
    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();

    try {
      if (StringUtils.isBlank(request.getRemoteUser())) {
        // request.logout();
        request.login(this.username, this.password);

      } else if (!request.getRemoteUser().equals(this.username)) {
        request.logout();
        request.login(this.username, this.password);
      }

      if (originalURL != null && originalURL.indexOf("service.jsf?") > 0) {
        externalContext.redirect(originalURL);
      } else {

        if (UserDAO.isProvider(this.username)) {
          String recentServiceId = serviceDAO.getProviderRecentServiceId(this.username);
          if (recentServiceId == null)
            externalContext.redirect(
                externalContext.getRequestContextPath() + "/provider/providerappointment.jsf");
          else
            externalContext.redirect(
                externalContext.getRequestContextPath()
                    + "/provider/serviceappointment.jsf?serviceId="
                    + recentServiceId);
        } else {
          String recentServiceId = serviceDAO.getUserRecentServiceId(this.username);
          if (recentServiceId == null)
            externalContext.redirect(
                externalContext.getRequestContextPath() + "/user/userappointment.jsf");
          else
            externalContext.redirect(
                externalContext.getRequestContextPath()
                    + "/user/appointment.jsf?serviceId="
                    + recentServiceId);
        }
      }
    } catch (Exception e) {
      // log.error(e.getCause(), e);
      WebUtil.addMessage(
          new FacesMessage(
              FacesMessage.SEVERITY_INFO,
              WebUtil.getMessage("login.failed.header"),
              WebUtil.getMessage("login.failed.message")));

      // context.addMessage(null, new FacesMessage("Login failed."));
    }
  }
Example #2
0
 public void process(ActionEvent event) {
   FacesContext fctx = FacesContext.getCurrentInstance();
   ExternalContext ectx = fctx.getExternalContext();
   HttpSession session = (HttpSession) ectx.getSession(true);
   String temp1 = session.getServletContext().getContextPath() + "/faces/issue2648-1.xhtml";
   String temp2 = session.getServletContext().getContextPath() + "/faces/issue2648-2.xhtml";
   try {
     boolean complete1 = fctx.getResponseComplete();
     ectx.redirect(temp1);
     boolean complete2 = fctx.getResponseComplete();
     ectx.redirect(temp2);
     boolean complete3 = fctx.getResponseComplete();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void registrarMatrinonio() throws IOException {
    getMatrimonio().setNormal(false);
    getMatrimonio().setHistorico(true);
    getMatrimonio().setEspecial(false);

    setMatrimonioDetalle(
        getMatrimonioService()
            .registrarMatrimonio(
                getMatrimonio(),
                getConsentimientoContrayenteUno(),
                getConsentimientoContrayenteDos()));
    if (getMatrimonioDetalle().getCodigoRespuesta().equals(0)) {
      FacesContext context = FacesContext.getCurrentInstance();
      context.getExternalContext().getFlash().setKeepMessages(true);

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO, "El registro se ha guardado correctamente.", ""));

      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
      externalContext.redirect(
          externalContext.getRequestContextPath().concat(ConstantesComunes.DETALLE_MATRIMONIO));
    } else {
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "Ocurri\u00f3 un error al guardar el registro.",
                  ""));
      RequestContext.getCurrentInstance().execute("errorDialog.show()");
    }
  }
  @Override
  public void handle() throws FacesException {
    final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();

    while (i.hasNext()) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      Throwable t = context.getException();

      final FacesContext fc = FacesContext.getCurrentInstance();
      final Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();

      try {
        System.out.printf(">>> Exception caught: %s", t.getMessage());
        t.printStackTrace();

        requestMap.put("exceptionMessage", t.getMessage());

        ExternalContext extContext = fc.getExternalContext();
        String url = extContext.encodeActionURL(extContext.getRequestContextPath() + "/500.xhtml");
        extContext.redirect(url);
      } catch (Exception e) {
        String errorPageLocation = "/WEB-INF/500.xhtml";
        fc.setViewRoot(fc.getApplication().getViewHandler().createView(fc, errorPageLocation));
        fc.getPartialViewContext().setRenderAll(false);
        fc.renderResponse();
      } finally {
        i.remove();
      }
    }

    getWrapped().handle();
  }
  public void registrarReconocimiento() throws IOException {

    setReconocimientoDetalle(
        getReconocimientoService()
            .registrarReconocimiento(getReconocimiento(), getPersonaOtorgaConsentimiento()));

    if (getReconocimientoDetalle().getCodigoRespuesta().equals(0)) {

      FacesContext context = FacesContext.getCurrentInstance();
      context.getExternalContext().getFlash().setKeepMessages(true);

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO, "El registro se ha guardado correctamente.", ""));

      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
      externalContext.redirect(
          externalContext.getRequestContextPath().concat(ConstantesComunes.DETALLE_RECONOCIMIENTO));

    } else {

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "Ocurri\u00f3 un error al guardar el registro.",
                  ""));
      RequestContext.getCurrentInstance().execute("errorDialog.show()");
    }
  }
  public void register(ActionEvent actionEvent) {
    CustomerDAO cdao = HibernateDAOFactory.instance().getCustomerDAO();

    RequestContext context = RequestContext.getCurrentInstance();
    FacesMessage msg = null;
    boolean loggedIn = false;
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();

    if (cdao.checklemail(email)) {
      Customer cs = new Customer();
      cs.setEmail(email);
      cs.setPass(pass);
      cs.setFullName(fullName);
      cs.setAddress(address);
      cs.setPhone(phone);
      cs.setVip(vip);
      cdao.add(cs);
      loggedIn = true;
      msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registe succes! Welcome", email);
      String url = "index.xhtml";
      try {
        ec.redirect(url);
      } catch (IOException ex) {

      }
    } else {
      loggedIn = false;
      msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Registe Error", "Invalid credentials");
    }

    FacesContext.getCurrentInstance().addMessage(null, msg);
    context.addCallbackParam("loggedIn", loggedIn);
  }
  public void payOrder() throws PayPalRESTException, IOException {
    // registering order and redirect  to payment service
    if (!(loginBean.isLinked())) {
      user.setActive(false);
    }
    user = userService.update(user);
    if (order.getDeliveryType() == DeliveryType.courierInKiev) {
      order.setAddressOrStorageNum(
          user.getCountry()
              + ", "
              + user.getCity()
              + ", "
              + user.getStreet()
              + ", "
              + user.getHouse()
              + ", кв. "
              + user.getApartment());
    }
    PaymentResultDto paymentResultDto = cartBean.buy(user.getId(), order);
    if (!paymentResultDto.approvalUrl.isEmpty()) {
      ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
      ec.redirect(paymentResultDto.approvalUrl);
    }

    orderMade = true;
    emailService.sendManagerNotificationByOrderId(paymentResultDto.orderId, getApplicationUri());
    //        return null;
  }
Example #8
0
  public void createBuyShowItem(ActionEvent event) throws IOException {
    System.err.println("test show item shopping cart!");
    setMemberAccount(
        (MemberAccount)
            FacesContext.getCurrentInstance()
                .getExternalContext()
                .getSessionMap()
                .get("currentMember"));
    System.err.println("select section num" + getTicketmanager().getSelectSectionNum());
    System.err.println("Show name : " + getTicketmanager().getSelectShowInfo().getName());
    System.err.println("section ticket : " + getTicketmanager().getSelectSectionTicket());

    String orderName =
        getTicketmanager().getSelectShowInfo().getName()
            + " ( section : "
            + getTicketmanager().getSelectSectionTicket().getSeatSection().getNum()
            + " )";
    System.err.println("Order Name : " + orderName);
    int quantity = getTicketmanager().getSelectSeats().size();
    System.err.println("ticket quantity : " + quantity);
    float price = getTicketmanager().getSelectSectionTicket().getPrice();
    System.err.println("ticket unit price : " + price);
    this.setShowItem(bimbl.addBuyShowItem(getMemberAccount(), orderName, quantity, (double) price));
    FacesMessage msg = new FacesMessage("Your ticket order is succesfully added to Shopping Cart!");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    ec.redirect("../CRM/Payment/cart.xhtml");
  }
 public void doRedirect(FacesContext fc, String redirectPage) {
   ExternalContext ec = fc.getExternalContext();
   try {
     ec.redirect(ec.getRequestContextPath() + (redirectPage != null ? redirectPage : ""));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #10
0
 protected void redirect(String url) {
   try {
     ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
     externalContext.redirect(url);
   } catch (IOException e) {
     log.error("Error: ", e);
   }
 }
Example #11
0
 public void processAjax(AjaxBehaviorEvent event) throws AbortProcessingException {
   FacesContext fctx = FacesContext.getCurrentInstance();
   ExternalContext ectx = fctx.getExternalContext();
   HttpSession session = (HttpSession) ectx.getSession(true);
   String temp1 = session.getServletContext().getContextPath() + "/faces/issue2648-1.xhtml";
   String temp2 = session.getServletContext().getContextPath() + "/faces/issue2648-2.xhtml";
   try {
     boolean complete1 = fctx.getResponseComplete();
     ectx.redirect(temp1);
     boolean complete2 = fctx.getResponseComplete();
     ectx.redirect(temp2);
     boolean complete3 = fctx.getResponseComplete();
   } catch (Exception e) {
     if (e instanceof IllegalStateException) {
       session.setAttribute("IllegalStateException", "true");
     }
   }
 }
Example #12
0
 public void logout() throws IOException {
   FacesContext context = FacesContext.getCurrentInstance();
   ExternalContext externalContext = context.getExternalContext();
   ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();
   faceContext = FacesContext.getCurrentInstance();
   httpServletRequest = (HttpServletRequest) faceContext.getExternalContext().getRequest();
   String redirectPath = "/faces/ositran/logueo.xhtml";
   externalContext.redirect(servletContext.getContextPath() + redirectPath);
 }
Example #13
0
  public String logout() {
    logOperationsController.save(OperazioniLog.LOGOUT, JSFUtils.getUserName(), "operazione logout");
    ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
    try {
      extCtx.redirect(extCtx.encodeActionURL(JSFUtils.getContextPath() + LOGOUT));
    } catch (Exception e) {

    }
    return null;
  }
Example #14
0
 private void redirect(String uri) {
   try {
     ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
     if (context != null) {
       context.redirect(uri);
     }
   } catch (IOException ioe) {
     showMessage(ioe.getMessage());
   }
 }
 public void update() throws IOException {
   FacesContext fc = FacesContext.getCurrentInstance();
   ExternalContext ec = fc.getExternalContext();
   if (selectedRoutes.size() > 3) {
     fc.addMessage(null, new FacesMessage("", "Please only select 3 routes maximum"));
   } else {
     accountManagementSessionBean.updatePreference(selectedRoutes, preferredDay, staffNo);
     ec.redirect("operationIndicatePreference.xhtml");
   }
 }
Example #16
0
 public void changeOperator() {
   FacesContext facesContext = FacesContext.getCurrentInstance();
   ExternalContext externalContext = facesContext.getExternalContext();
   String requestURI = ((HttpServletRequest) externalContext.getRequest()).getRequestURI();
   try {
     externalContext.redirect(requestURI);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #17
0
 /** refreshes the page */
 public void forceRefresh() {
   ExternalContext externalContext = getFacesContext().getExternalContext();
   if (externalContext != null) {
     try {
       externalContext.redirect("visualiser.jsp");
     } catch (IOException ioe) {
       // ok - do nothing
     }
   }
 }
Example #18
0
 public static void redirect(FacesContext context, String path) {
   RedirectScope.setRedirectingPath(context, path);
   ExternalContext externalContext = context.getExternalContext();
   try {
     externalContext.redirect(externalContext.encodeActionURL(path));
   } catch (IOException e) {
     throw new FacesException(e.getMessage(), e);
   }
   context.responseComplete();
   context.renderResponse();
 }
Example #19
0
  public void logoutSesionInvalidate() throws IOException {
    faceContext = FacesContext.getCurrentInstance();

    ExternalContext externalContext = faceContext.getExternalContext();
    ServletContext servletContext = (ServletContext) faceContext.getExternalContext().getContext();
    httpServletRequest = (HttpServletRequest) faceContext.getExternalContext().getRequest();
    HttpSession session = httpServletRequest.getSession();
    session.invalidate();
    String redirectPath = "/faces/ositran/logueo.xhtml";
    externalContext.redirect(servletContext.getContextPath() + redirectPath);
  }
Example #20
0
  /**
   * If it is an internal redirect (to the application itself) generates the state, stores it in
   * session and adds corresponding parameter to url.
   */
  @Override
  public void redirect(final String url) throws IOException {

    // Add state to url
    String finalUrl = redirectHelper.addHDIVStateToURL(url);
    if (log.isDebugEnabled()) {
      log.debug("Redirecting to:" + finalUrl);
    }

    wrapped.redirect(finalUrl);
  }
  // Redireciona Pagina
  private void redirect(String path) {
    try {
      FacesContext context = FacesContext.getCurrentInstance();
      ExternalContext externalContext = context.getExternalContext();
      String requestContextPath = externalContext.getRequestContextPath();

      externalContext.redirect(requestContextPath + path);
      context.responseComplete();
    } catch (IOException e) {

      throw new RuntimeException(e);
    }
  }
Example #22
0
 public void redirect(String location) {
   try {
     FacesContext ctx = FacesContext.getCurrentInstance();
     ExternalContext extContext = ctx.getExternalContext();
     String url =
         extContext.encodeActionURL(
             ctx.getApplication().getViewHandler().getActionURL(ctx, location));
     extContext.redirect(url);
   } catch (IOException ex) {
     LoggerService.log(ex);
   } catch (java.lang.IllegalStateException ex) {
   }
 }
 @Override
 public void afterPhase(PhaseEvent event) {
   FacesContext facesContext = event.getFacesContext();
   if (facesContext.getViewRoot() == null) {
     try {
       ExternalContext econtext = facesContext.getExternalContext();
       String contextPath = ((ServletContext) econtext.getContext()).getContextPath();
       econtext.redirect(contextPath + "/");
     } catch (IOException ex) {
       Logger.getLogger(DefaultPhaseListener.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
Example #24
0
  public String doit() {
    if ("searchQuestionBank".equals(outcome)) {
      try {
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        context.redirect("sakai.questionbank.client.helper/authorIndex");
      } catch (Exception e) {
        log.error("fail to redirect to question bank: " + e.getMessage());
      }
    }

    // navigation for ItemModifyListener
    return outcome;
  }
Example #25
0
  /**
   * Determine the next view based on the current view (<code>from-view-id</code> stored in <code>
   * FacesContext</code>), <code>fromAction</code> and <code>outcome</code>.
   *
   * @param context The <code>FacesContext</code>
   * @param fromAction the action reference string
   * @param outcome the outcome string
   */
  public void handleNavigation(FacesContext context, String fromAction, String outcome) {
    if (context == null) {
      String message =
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context");
      throw new NullPointerException(message);
    }
    if (outcome == null) {
      return; // Explicitly remain on the current view
    }
    CaseStruct caseStruct = getViewId(context, fromAction, outcome);
    ExternalContext extContext = context.getExternalContext();
    if (caseStruct != null) {
      ViewHandler viewHandler = Util.getViewHandler(context);
      assert (null != viewHandler);

      if (caseStruct.navCase.isRedirect()) {
        // perform a 302 redirect.
        String newPath = viewHandler.getActionURL(context, caseStruct.viewId);
        try {
          if (logger.isLoggable(Level.FINE)) {
            logger.fine(
                "Redirecting to path "
                    + newPath
                    + " for outcome "
                    + outcome
                    + "and viewId "
                    + caseStruct.viewId);
          }
          // encode the redirect to ensure session state
          // is maintained
          extContext.redirect(extContext.encodeActionURL(newPath));
        } catch (java.io.IOException ioe) {
          if (logger.isLoggable(Level.SEVERE)) {
            logger.log(Level.SEVERE, "jsf.redirect_failed_error", newPath);
          }
          throw new FacesException(ioe.getMessage(), ioe);
        }
        context.responseComplete();
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("Response complete for " + caseStruct.viewId);
        }
      } else {
        UIViewRoot newRoot = viewHandler.createView(context, caseStruct.viewId);
        context.setViewRoot(newRoot);
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("Set new view in FacesContext for " + caseStruct.viewId);
        }
      }
    }
  }
Example #26
0
 /**
  * Wykonuje akcję przekazaną w argumencie. W razie wyjątku ApplicationBaseException przechwyuje go
  * i przekierowuje do strony /error/applicationError przez FacesContext i ustawia w ContextMapie
  * komunikat do
  * wyświetlenia.error/applicationError.xhtml?uuid=ee7f5392-7c00-452b-a727-121a267900ae
  *
  * @param action Akcja do wykonania, która może zakończyć się ApplicationBaseException.
  */
 protected void expectApplicationException(ApplicationErrorAction action) {
   try {
     action.run();
   } catch (ApplicationBaseException e) {
     setContext(ApplicationErrorBean.class, bean -> bean.setExceptionMessage(e.getCode()));
     try {
       ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
       String redirectResource = "/error/applicationError.xhtml?uuid=" + getUuid();
       externalContext.redirect(externalContext.getRequestContextPath() + redirectResource);
     } catch (IOException e1) {
       throw new RuntimeException(e1);
     }
   }
 }
Example #27
0
 public void continuar(String page) {
   FacesMessage msg = null;
   final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
   try {
     externalContext.redirect(page);
   } catch (final IOException e) {
     msg =
         new FacesMessage(
             FacesMessage.SEVERITY_WARN,
             Messages.getString("LoginBean.message.error.login"), // $NON-NLS-1$
             Messages.getString("LoginBean.message.error.login.detail")); // $NON-NLS-1$
     FacesContext.getCurrentInstance().addMessage(null, msg);
     LogManager.error(Messages.getString("LoginBean.log.message.error.login"), e); // $NON-NLS-1$
   }
 }
Example #28
0
 public String processAddAttachRedirect() {
   try {
     filePickerList = EntityManager.newReferenceList();
     ToolSession currentToolSession = SessionManager.getCurrentToolSession();
     currentToolSession.setAttribute(
         "filepicker.attach_cardinality", FilePickerHelper.CARDINALITY_SINGLE);
     currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
     ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
     context.redirect("sakai.filepicker.helper/tool");
     return null;
   } catch (Exception e) {
     LOG.error(this + ".processAddAttachRedirect - " + e);
     e.printStackTrace();
     return null;
   }
 }
Example #29
0
  public void onPageLoad() {
    initUserContext();
    if (!checkUserAccess(userContext.getUserCode(), this.getClass().getName())) {
      FacesContext fctx = FacesContext.getCurrentInstance();
      ExternalContext ectx = fctx.getExternalContext();
      String url =
          ((HttpServletRequest) ectx.getRequest()).getContextPath()
              + "/pages/common/restrictionAccess.jsf";
      try {
        ectx.redirect(url);
      } catch (IOException e) {

        e.printStackTrace();
      }
    }
    ;
  }
Example #30
0
  /** Launch the print helper */
  public String print() {

    try {
      AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean");
      ToolSession currentToolSession = SessionManager.getCurrentToolSession();
      currentToolSession.setAttribute("QB_assessemnt_id", assessmentBean.getAssessmentId());
      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
      context.redirect(
          "sakai.questionbank.printout.helper/printAssessment?assessmentId="
              + assessmentBean.getAssessmentId()
              + "&actionString=previewAssessment");
    } catch (Exception e) {
      log.error("fail to redirect to assessment print out: " + e.getMessage());
    }

    return outcome;
  }