Пример #1
0
  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."));
    }
  }
  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()");
    }
  }
  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()");
    }
  }
  @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 doRedirect(FacesContext fc, String redirectPage) {
   ExternalContext ec = fc.getExternalContext();
   try {
     ec.redirect(ec.getRequestContextPath() + (redirectPage != null ? redirectPage : ""));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #6
0
  /**
   * This code is currently common to all {@link ViewHandlingStrategy} instances.
   *
   * @see ViewHandler#getResourceURL(javax.faces.context.FacesContext, String)
   */
  public String getResourceURL(FacesContext context, String path) {

    ExternalContext extContext = context.getExternalContext();
    if (path.charAt(0) == '/') {
      return (extContext.getRequestContextPath() + path);
    } else {
      return path;
    }
  }
Пример #7
0
  /**
   * This code is currently common to all {@link ViewHandlingStrategy} instances.
   *
   * @see ViewHandler#getActionURL(javax.faces.context.FacesContext, String)
   */
  public String getActionURL(FacesContext context, String viewId) {

    Util.notNull("context", context);
    Util.notNull("viewId", viewId);

    if (viewId.charAt(0) != '/') {
      String message =
          MessageUtils.getExceptionMessageString(MessageUtils.ILLEGAL_VIEW_ID_ID, viewId);
      if (logger.isLoggable(Level.SEVERE)) {
        logger.log(Level.SEVERE, "jsf.illegal_view_id_error", viewId);
      }
      throw new IllegalArgumentException(message);
    }

    // Acquire the context path, which we will prefix on all results
    ExternalContext extContext = context.getExternalContext();
    String contextPath = extContext.getRequestContextPath();

    // Acquire the mapping used to execute this request (if any)
    String mapping = Util.getFacesMapping(context);

    // If no mapping can be identified, just return a server-relative path
    if (mapping == null) {
      return (contextPath + viewId);
    }

    // Deal with prefix mapping
    if (Util.isPrefixMapped(mapping)) {
      if (mapping.equals("/*")) {
        return (contextPath + viewId);
      } else {
        return (contextPath + mapping + viewId);
      }
    }

    // Deal with extension mapping
    int period = viewId.lastIndexOf('.');
    if (period < 0) {
      return (contextPath + viewId + mapping);
    } else if (!viewId.endsWith(mapping)) {

      for (String ext : configuredExtensions) {
        if (viewId.endsWith(ext)) {
          return (contextPath + viewId.substring(0, viewId.indexOf(ext)) + mapping);
        }
      }

      return (contextPath + viewId.substring(0, period) + mapping);
    } else {
      return (contextPath + viewId);
    }
  }
  // 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);
    }
  }
Пример #9
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);
     }
   }
 }
Пример #10
0
 public String getApplicationUri() {
   try {
     FacesContext ctxt = FacesContext.getCurrentInstance();
     ExternalContext ext = ctxt.getExternalContext();
     URI uri =
         new URI(
             ext.getRequestScheme(),
             null,
             ext.getRequestServerName(),
             ext.getRequestServerPort(),
             ext.getRequestContextPath(),
             null,
             null);
     return uri.toASCIIString();
   } catch (URISyntaxException e) {
     throw new FacesException(e);
   }
 }
Пример #11
0
  public static String getResourceURL(String url, FacesContext context) {
    if (null == url) {
      return null;
    }

    Application application = context.getApplication();
    ExternalContext externalContext = context.getExternalContext();

    String value = url;

    if (value.length() == 0
        || value.charAt(0) != '/'
        || !value.startsWith(externalContext.getRequestContextPath())) {
      value = application.getViewHandler().getResourceURL(context, value);
    }

    return externalContext.encodeResourceURL(value);
  }
Пример #12
0
  public void logout() {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext externalContext = context.getExternalContext();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    String userId = request.getRemoteUser();
    if (userId != null) {
      try {
        request.logout();
      } catch (ServletException e) {
        log.error(e.getCause(), e);
        context.addMessage(null, new FacesMessage("Logout failed."));
      }
    }

    try {
      externalContext.redirect(externalContext.getRequestContextPath() + "/index.jsf");
    } catch (IOException e) {
      log.error(e.getCause(), e);
      context.addMessage(null, new FacesMessage("redirect failed."));
    }
  }
  @Override
  public void afterPhase(PhaseEvent event) {
    ExceptionHandler exceptionHandler = event.getFacesContext().getExceptionHandler();
    if (Iterables.isEmpty(exceptionHandler.getUnhandledExceptionQueuedEvents())) {
      return;
    }

    try {
      new OptimisticLockExceptionHandler(exceptionHandler).handle();

      FacesContext faces = FacesContext.getCurrentInstance();
      String nextUrl = ConversationManager.getInstance().getCurrentConversation().nextUrl();

      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
      String url = externalContext.getRequestContextPath() + nextUrl;
      faces.getExternalContext().redirect(url);
      faces.responseComplete();
    } catch (IOException e) {
      log.error("Failed to redirect to context page in render response phase", e);
    }
  }
Пример #14
0
  @PostConstruct
  public void init() {
    serviceDAO = new ServiceDAO();
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    // originalURL = (String)
    // externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);

    originalURL = (String) externalContext.getRequestHeaderMap().get("referer");

    if (originalURL == null) {
      originalURL = externalContext.getRequestContextPath() + "/index.jsf";
    } else {
      String originalQuery =
          (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_QUERY_STRING);

      if (originalQuery != null) {
        originalURL += "?" + originalQuery;
      }
    }

    // log.debug("originalURL==>" + originalURL);
  }
  /** Metodo para guardar un nuevo registro de Defuncion */
  public void guardaRegistroHistoricoDefuncion() throws IOException {
    getDefuncionDTO().setNormal(false);
    getDefuncionDTO().setHistorico(true);
    getDefuncionDTO().setEspecial(false);

    System.out.println("Entro +++++++++++++++++++++++++++++++++++++");
    setDefuncionDetalle(
        getDefuncionService()
            .guardarDefuncion(
                getDefuncionDTO(),
                getExistenciaConyuge(),
                getExistenciaProgenitorUno(),
                getExistenciaProgenitorDos()));
    if (getDefuncionDetalle().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_DEFUNCION));
    } else {

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "Ocurri\u00f3 un error al guardar el registro.",
                  ""));
      RequestContext.getCurrentInstance().execute("errorDialog.show()");
    }
  }