public String process() {
   if (!this.loggedIn) {
     try {
       this.loggedIn =
           this.authenticateObject.check(new AuthenticateDTO(this.login, this.password));
     } catch (EJBException ejbex) {
       this.loggedIn = false;
       System.out.println(ejbex.toString());
     }
   } else {
     this.loggedIn = false;
   }
   if (this.loggedIn) {
     ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest())
         .getSession(true);
     this.cartObject.initialize();
   } else {
     FacesContext facesContext = FacesContext.getCurrentInstance();
     ExternalContext externalContext = facesContext.getExternalContext();
     Locale loc = externalContext.getRequestLocale();
     externalContext.invalidateSession();
     facesContext.getViewRoot().setLocale(loc);
     if (this.cartObject != null) {
       this.cartObject.setClientId(null);
       this.cartObject.setMerchandiseId(null);
       this.cartObject.setAmount(null);
       this.cartObject.destroy();
     }
     this.currencyObject.setLocalizationLocale(loc);
   }
   return null;
 }
Esempio n. 2
0
  private void restoreView(FacesContext context) throws FacesException {
    Application app = context.getApplication();

    if (app instanceof ApplicationImpl) ((ApplicationImpl) app).initRequest();

    ViewHandler view = app.getViewHandler();

    view.initView(context);

    UIViewRoot viewRoot = context.getViewRoot();

    if (viewRoot != null) {
      ExternalContext extContext = context.getExternalContext();

      viewRoot.setLocale(extContext.getRequestLocale());

      doSetBindings(context.getELContext(), viewRoot);

      return;
    }

    String viewId = calculateViewId(context);

    String renderKitId = view.calculateRenderKitId(context);

    RenderKitFactory renderKitFactory =
        (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);

    RenderKit renderKit = renderKitFactory.getRenderKit(context, renderKitId);

    ResponseStateManager stateManager = renderKit.getResponseStateManager();

    if (stateManager.isPostback(context)) {
      viewRoot = view.restoreView(context, viewId);

      if (viewRoot != null) {
        doSetBindings(context.getELContext(), viewRoot);
      } else {
        // XXX: backward compat issues with ViewHandler and StateManager

        // throw new ViewExpiredException(L.l("{0} is an expired view", viewId));

        context.renderResponse();

        viewRoot = view.createView(context, viewId);

        context.setViewRoot(viewRoot);
      }

      context.setViewRoot(viewRoot);
    } else {
      context.renderResponse();

      viewRoot = view.createView(context, viewId);

      context.setViewRoot(viewRoot);
    }
  }
  public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {

    if (value != null) {
      StringBuilder integerChars = new StringBuilder(value.length());
      StringBuilder invalidChars = new StringBuilder(value.length());

      for (int i = 0; i < value.length(); i++) {
        char curChar = value.charAt(i);

        if (Character.isDigit(curChar)) {
          integerChars.append(curChar);
        } else if ((curChar != '-')
            && (curChar != '(')
            && (curChar != ')')
            && (curChar != '.')
            && (curChar != '+')
            && (curChar != ' ')) {

          invalidChars.append(curChar);
        }
      }

      if (invalidChars.length() > 0) {
        ExternalContext externalContext = facesContext.getExternalContext();

        Locale locale = externalContext.getRequestLocale();

        String summary = LanguageUtil.get(locale, "the-following-are-invalid-characters");

        summary += " " + invalidChars.toString();

        FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null);

        throw new ConverterException(facesMessage);
      } else if ((integerChars.length() == 10)) {
        StringBuilder unitedStatesPhoneNumber = new StringBuilder(_unitedStatesFormat.length());

        int integerDigitIndex = 0;

        for (int i = 0; i < _unitedStatesFormat.length(); i++) {
          char curChar = _unitedStatesFormat.charAt(i);

          if (curChar == '#') {
            unitedStatesPhoneNumber.append(integerChars.charAt(integerDigitIndex++));
          } else {
            unitedStatesPhoneNumber.append(curChar);
          }
        }

        return unitedStatesPhoneNumber.toString();
      }
    }

    return value;
  }