Package org.primefaces.context

Examples of org.primefaces.context.RequestContext


    private String username;
    private String password;
   
    /** Creates a new instance of loginSystem */
    public void login(ActionEvent actionEvent) {
        RequestContext context = RequestContext.getCurrentInstance();
        FacesMessage msg = null;
        boolean loggedIn = false;
        if (username.length() == 0) {
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "User Not null .");
        } else if (password.length() == 0) {
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Password Not null .");
        } else {
            this.login = this.loginFacade.loginSystem(username, password);
            if (login != null) {
                if (login.getRoles().equals("member")) {
                    if (login.getStatus().equals("off")) {
                        loggedIn = false;
                        msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "This account has been locked .");
                    } else {
                        loggedIn = true;
                        operationSession.ganGiaTriChoSession("user", this.login.getUsername());
                        operationSession.ganGiaTriChoSession("role", this.login.getRoles());
                        msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", login.getUsername());
                    }
                } else if (login.getRoles().equals("staff")) {
                    if (login.getStatus().equals("off")) {
                        loggedIn = false;
                        msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "This account has been locked .");
                    } else {
                        loggedIn = true;
                        operationSession.ganGiaTriChoSession("user", this.login.getUsername());
                        operationSession.ganGiaTriChoSession("role", this.login.getRoles());
                        msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", login.getUsername());
                    }
                } else if (login.getRoles().equals("admin")) {
                    loggedIn = true;
                    operationSession.ganGiaTriChoSession("user", this.login.getUsername());
                    operationSession.ganGiaTriChoSession("role", this.login.getRoles());
                    msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", login.getUsername());
                } else {
                }
            } else {
                msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "User or Password Error");
                this.login.setPassword(null);
            }
        }
        FacesContext.getCurrentInstance().addMessage(null, msg);
        context.addCallbackParam("loggedIn", loggedIn);
    }
View Full Code Here


    this.delegate = delegate;
  }

  @Override
  public void redirect(String url) throws IOException {
    RequestContext requestContext = RequestContext.getCurrentInstance();
   
    if(requestContext.isAjaxRequest()) {     
      LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
      Lifecycle lifecycle = factory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
      PrimeFacesPhaseListener listener = new PrimeFacesPhaseListener();
      PhaseEvent phaseEvent = new PhaseEvent(FacesContext.getCurrentInstance(), PhaseId.RENDER_RESPONSE, lifecycle);

      requestContext.setAjaxRedirectUrl(url);
     
      listener.beforePhase(phaseEvent)//send ajax redirect request
     
      RequestContext.getCurrentInstance().release();
    } else {
View Full Code Here

      }
    }
  }
 
  private void handleAjaxRequest(FacesContext facesContext) throws IOException {
    RequestContext requestContext = RequestContext.getCurrentInstance();
    Map<String,String> params = facesContext.getExternalContext().getRequestParameterMap();
   
    if(logger.isLoggable(Level.FINE)) {
      logger.fine("Processing PrimeFaces ajax request");
    }
   
    initPartialRenderView(facesContext);
   
    boolean isPPRRequest = !params.containsKey(Constants.PARTIAL_SOURCE_PARAM);
   
    if(isPPRRequest) {
      String[] idsToUpdate = getIdsToUpdate(facesContext, requestContext);
     
      ServletResponse response = (ServletResponse) facesContext.getExternalContext().getResponse();
      response.setContentType("text/xml");
     
      ResponseWriter writer = facesContext.getResponseWriter();
      try {
        writer.write("<?xml version=\"1.0\" encoding=\"" + response.getCharacterEncoding() + "\"?>");
        writer.write("<partialResponse>");
       
        if(requestContext.getAjaxRedirectUrl() != null) {
          writer.write("<redirect-url>" + RequestContext.getCurrentInstance().getAjaxRedirectUrl() + "</redirect-url>");
        } else {
          if(idsToUpdate != null) {
            writeComponents(facesContext, idsToUpdate);
          }
         
          writeState(facesContext);
         
          //Send request callback parameters
          requestContext.addCallbackParam("validationFailed", facesContext.isValidationFailed());
          writeCallbackParams(facesContext, requestContext);
        }

        writer.write("</partialResponse>");
      }catch(IOException exception) {
View Full Code Here

        try {
            if(!statusChat){
                throw new MensagemException("Você tem que ficar online para abrir um chat de conversa!", Constants.MSG_ALERT);
            }
           
            RequestContext requestContext = RequestContext.getCurrentInstance();
            Map<String, String> params = getExternalContext().getRequestParameterMap();
            final String uid = params.get("uid");

            Operadores op = chatOperadores.getOperadoresMap().get(uid);
            if (op != null && !op.getLogin().equals(operador.getLogin()) && op.isProntoConversa()) {
                warn("O operador " + op.getLogin() + " já esta em atendimento!");
                requestContext.update(":painelAdminForm:msgs");
                return;
            }
            Visitantes v = (Visitantes) CollectionUtils.find(chatVisitantes.getVisitantesList(), new Predicate() {
                @Override
                public boolean evaluate(Object input) {
                    Visitantes visitantes = (Visitantes) input;
                    return visitantes.getUniqueId().equals(uid);
                }
            });
            Object o = chatOperadores.getOperadoresMap().get(uid);
            if (o == null) {
                Mensagens mensagens = new Mensagens();
                mensagens.setMensagem("Pronto, em que posso lhe ajudar!");
                mensagens.setOperador(operador);
                mensagens.setUniqueId(uid);
                ConversaHistorico conversaHistorico = new ConversaHistorico();
                conversaHistorico.setNome(operador.getNome());
                conversaHistorico.setLogin(operador.getLogin());
                conversaHistorico.setDataMensagem(new Date(System.currentTimeMillis()));
                conversaHistorico.setDescricaoConversa(mensagens.getMensagem());

                conversaHistorico.setUniqueId(v.getUniqueId());
                conversaHistoricoSBeanLocal.salvar(conversaHistorico);
                chatMensagens.add(mensagens);
            }
            v.setLoginOperador(operador.getLogin());
            visitantesSBeanLocal.alterar(v);
            operador.setVisitantes(v);
            operador.setIdUnique(v.getUniqueId());
            chatVisitantes.addVisistanteUID(uid, v);
            operador.setProntoConversa(true);
            chatOperadores.addOpMap(uid, operador);
            List<Operadores> operadoresList = chatOperadores.getOperadoresList();
            for (Operadores operadores : operadoresList) {
                if (operadores.getLogin().equals(operador.getLogin())) {
                    operadores.setProntoConversa(true);
                    statusChat=true;
                    break;
                }
            }
            List<Visitantes> visitantesList = chatVisitantes.getVisitantesList();
            for (Visitantes visit : visitantesList) {
                if (visit.getLoginVisitante().equals(v.getLoginVisitante())) {
                    visit.setEmAtendimento(true);
                    break;
                }
            }
            requestContext.execute("abrirJanelaBatePapo('" + uid + "','" + v.getLoginVisitante() + "')");

        } catch (Exception ex) {
            tratamentoException.tratar(ex);
        }
    }
View Full Code Here

        if(!content.getStyles().contains(style)) {
            content.getStyles().add(style);
            contentManager.saveContent(content);

            RequestContext requestContext = RequestContext.getCurrentInstance();
            requestContext.addPartialUpdateTarget(event.getDropId());
            requestContext.addPartialUpdateTarget(stylePanel.getClientId(facesContext));
            requestContext.addPartialUpdateTarget(editor.getClientId(facesContext));
            requestContext.addPartialUpdateTarget(dropper.getClientId(facesContext));
            requestContext.addPartialUpdateTarget(theTreeComponent.getClientId(facesContext));
        }
        makeContentCss();
    }
View Full Code Here

        if(content.getStyles().contains(style)) {
            content.getStyles().remove(style);
            contentManager.saveContent(content);
        }

        RequestContext requestContext = RequestContext.getCurrentInstance();
        requestContext.addPartialUpdateTarget(editor.getClientId(facesContext));
        requestContext.addPartialUpdateTarget(stylePanel.getClientId(facesContext));
        requestContext.addPartialUpdateTarget(dropper.getClientId(facesContext));
        requestContext.addPartialUpdateTarget(theTreeComponent.getClientId(facesContext));

        makeContentCss();
    }
View Full Code Here

            }
        }
    }

    private void addGroupUpdateTarget(String clientId) {
        RequestContext requestContext = RequestContext.getCurrentInstance();
        if(clientId.matches(".*[0-9]+$"))
            clientId = clientId.replaceAll(":[0-9]+$", "");
        requestContext.addPartialUpdateTarget(clientId);
    }
View Full Code Here

        try {
            if (event instanceof PostAddToViewEvent) {
                PostAddToViewEvent postAddToViewEvent = (PostAddToViewEvent) event;

                FacesContext context = FacesContext.getCurrentInstance();
                RequestContext requestContext = RequestContext.getCurrentInstance();
                ConfigContainer config = requestContext.getApplicationContext().getConfig();

                if (config.isTransformMetadataEnabled() && config.isBeanValidationAvailable()) {
                    BV_INPUT_METADATA_TRANSFORMER.transform(context, requestContext, postAddToViewEvent.getComponent());
                }
View Full Code Here

            }
        }

        //Metadata for callback
        if(table.isPaginator()) {
            RequestContext requestContext = RequestContext.getCurrentInstance();

            if(requestContext != null) {
                requestContext.addCallbackParam("totalRecords", filteredData.size());
            }
        }

        //save filtered data
        table.updateFilteredValue(context, filteredData);
View Full Code Here

        this.base = base;
    }
       
    public void processAction(ActionEvent event) throws AbortProcessingException {
        UIComponent source = event.getComponent();
        RequestContext context = RequestContext.getCurrentInstance();
        Map<Object,Object> attrs = context.getAttributes();
        if(source instanceof Widget) {
            attrs.put(Constants.DIALOG_FRAMEWORK.SOURCE_WIDGET, ((Widget) source).resolveWidgetVar());
        }
       
        attrs.put(Constants.DIALOG_FRAMEWORK.SOURCE_COMPONENT, source.getClientId());
View Full Code Here

TOP

Related Classes of org.primefaces.context.RequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.