Java Code Examples for javax.faces.context.FacesContext.getCurrentInstance()

The following are Jave code examples for showing how to use getCurrentInstance() of the javax.faces.context.FacesContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: NICON   File: ContaBancoBean.java   View Source Code Vote up 8 votes
public void regContaBanco(){
    FacesContext facesContext = FacesContext.getCurrentInstance();
    contaBanco.setIdtipoConta(Int(facesContext.getExternalContext().getRequestParameterMap().get("tipoconta")));
    contaBanco.setIdtipoContaContabilistica(Int(facesContext.getExternalContext().getRequestParameterMap().get("contacontabalistica")));
    contaBanco.setIdbanco(Int(facesContext.getExternalContext().getRequestParameterMap().get("banco")));
    contaBanco.setIdTipoMoeda(Int(facesContext.getExternalContext().getRequestParameterMap().get("tipomoeda")));
    contaBanco.setNumConta(facesContext.getExternalContext().getRequestParameterMap().get("numconta"));
    String stra[] = new ContaBancoDao().regAccount(contaBanco);
    if(stra != null && "true".equals(stra[0])){
        RequestContext.getCurrentInstance().execute("limparCBForm()");
        listContaBanco = new ContaBancoDao().getListContaBanco(null);
        Validacao.atualizar("accountTableForm", "tableCantaBanco");
        Message.addInfoMsg("Nova Conta Banco registada com sucesso!","changePassword", "growlChangePassword");
    }else if(stra != null && "false".equals(stra[0]))
    { Message.addErrorMsg(stra[1],"changePassword", "growlChangePassword"); }
    RequestContext.getCurrentInstance().execute("$('.modalProcess').hide()");
}
 
Example 2
Project: oscm   File: ManageLanguageCtrl.java   View Source Code Vote up 6 votes
private void createResponse(byte[] buf) throws IOException {
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) fc
            .getExternalContext().getResponse();

    String filename = generateFileName();

    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachement; filename=\""
            + filename + "\"");
    response.setContentLength(buf.length);
    OutputStream out;
    out = response.getOutputStream();
    out.write(buf);
    out.flush();
    out.close();
    fc.responseComplete();
}
 
Example 3
Project: myfaces-trinidad   File: ClientIdCachingTest.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
public void testBasic()
{
  TestNamingContainer a = new TestNamingContainer(); a.setId("a");
  TestNamingContainer b = new TestNamingContainer(); b.setId("b");
  TestNamingContainer d = new TestNamingContainer(); d.setId("d");
  TestPanel e = new TestPanel(); e.setId("e");
  TestPanel g = new TestPanel(); g.setId("g");
                                 
  FacesContext context = FacesContext.getCurrentInstance();
  context.getViewRoot().getChildren().add(a);

  a.getChildren().add(b);
  b.getChildren().add(d);
  b.getChildren().add(g);
  d.getChildren().add(e);
  
  
  assertEquals("a:b:d:e", e.getClientId(context));
}
 
Example 4
Project: myfaces-trinidad   File: ServletExternalContext.java   View Source Code Vote up 6 votes
@Override
public void redirect(final String url) throws IOException
{
  _checkResponse();

  if (_servletResponse instanceof HttpServletResponse)
  {
    _httpServletResponse.sendRedirect(url);

    FacesContext fc = FacesContext.getCurrentInstance();
    if (fc != null)
    {
      fc.responseComplete();
    }
  }
  else
  {
    throw new IllegalArgumentException(_LOG.getMessage(
      "ONLY_HTTPSERVLETRESPONSE_SUPPORTED"));
  }
}
 
Example 5
Project: parabuild-ci   File: JsfCreator.java   View Source Code Vote up 5 votes
public Object getInstance() throws InstantiationException
{
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext == null)
    {
        log.error("Object " + getManagedBeanName() + " cannot be created since the faces context is null");
        return null;
    }

    Application application = facesContext.getApplication();
    Object resolvedObject = null;

    if (isVBExpression(getManagedBeanName()))
    {
        ValueBinding vb = application.createValueBinding(getManagedBeanName());
        if (vb != null)
        {
            resolvedObject = vb.getValue(facesContext);
        }
    }
    else
    {
        VariableResolver resolver = application.getVariableResolver();
        resolvedObject = resolver.resolveVariable(facesContext, getManagedBeanName());
    }

    return resolvedObject;
}
 
Example 6
Project: myfaces-trinidad   File: MRequestContext.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> getViewMap(boolean create)
{
  // Note: replace this method body with a call to UIViewRoot.getViewMap(boolean) when
  // Trinidad is upgraded to use JSF 2.0

  FacesContext facesContext = FacesContext.getCurrentInstance();
  UIViewRoot viewRoot = facesContext.getViewRoot();
  Map<String, Object> viewMap = null;

  if (viewRoot != null)
  {
    Map<String, Object> attrs = viewRoot.getAttributes();

    viewMap = (Map<String, Object>)attrs.get(_VIEW_MAP_KEY);
    if (viewMap == null && create)
    {
      // Note, it is not valid to refer to the request context from outside of the request's
      // thread. As such, synchronization and thread safety is not an issue here.
      // This coincides with the JSF 2.0 code not using syncronization and using the non-thread
      // safe HashMap.
      viewMap = new HashMap<String, Object>();
      attrs.put(_VIEW_MAP_KEY, viewMap);
    }
  }

  return viewMap;
}
 
Example 7
Project: NICON   File: EmpresaBean.java   View Source Code Vote up 5 votes
public void handleFileUpload(String imagem) 
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        
        try
        {       
         
//            System.err.println(typeImagem(imagem));
            byte[] bd = org.apache.poi.util.IOUtils.toByteArray(typeImagem(imagem).getInputStream());
           
            ServletContext scontext = (ServletContext) facesContext.getExternalContext().getContext();
            String arquivo = scontext.getRealPath("/Imagem/");
//            System.err.println(arquivo);
            File f = new File(arquivo);
            for(File dd: f.listFiles())
                if(dd.getName().contains(SessionUtil.getUserlogado().getNomeAcesso()+imagem))
                    dd.delete();
            
            try (FileOutputStream fos = new FileOutputStream(arquivo+"/"+SessionUtil.getUserlogado().getNif()+imagem+ii+".jpg")) 
            {fos.write(bd);}
            
            alterarImagem(imagem,"/Imagem/"+SessionUtil.getUserlogado().getNif()+imagem+ii+".jpg");
            
            ii++;
            RequestContext.getCurrentInstance().update("empresaReg:"+imagem);
        }
        catch (IOException ex) 
        {
            Logger.getLogger(UtilizadorBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
Example 8
Project: myfaces-trinidad   File: ChangeBean.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private static void _removeChild(UIComponent uic, String removableChildId)
{
  UIComponent removableChild = _findChildById(uic, removableChildId);
  if (removableChild != null)
  {
    List<UIComponent> children = uic.getChildren();
    children.remove(removableChild);
    ComponentChange rca = new RemoveChildComponentChange(removableChildId);
    FacesContext fc = FacesContext.getCurrentInstance();
    ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
    apm.addComponentChange(fc, uic, rca);
  }
}
 
Example 9
Project: myfaces-trinidad   File: DialogRequest.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public DialogRequest(
  UIViewRoot         targetRoot,
  String             clientId,
  String             formId,
  Map<String,Object> dialogProperties,
  boolean            usePopup
  )
{
  _clientId = clientId;
  _formId   = formId;
  _usePopup = usePopup;

  if (dialogProperties == null)
    dialogProperties = Collections.emptyMap();

  Object width = dialogProperties.get("width");
  Object height = dialogProperties.get("height");

  FacesContext context = FacesContext.getCurrentInstance();

  String url;
  
  if (usePopup)
  {
    url = context.getApplication().getViewHandler().getActionURL(context, targetRoot.getViewId());
  }
  else
  {
    url = FredJSP.getRedirectURL(context,
                                targetRoot,
                                CoreRenderer.toString(width),
                                CoreRenderer.toString(height));
  }
  
  PageFlowScopeProvider provider = RequestContext.getCurrentInstance().getPageFlowScopeProvider();
  _url = context.getExternalContext().encodeActionURL(provider.encodeDialogPageFlowScopeURL(context, url));
  
  _dialogProperties  = dialogProperties;
}
 
Example 10
Project: myfaces-trinidad   File: AccountData.java   View Source Code Vote up 5 votes
/**
 * Process login. Connect to server and move to folder display page.
 */
public String login()
{
  try
  {
    // login to the IMAP server
    Properties props = new Properties();
    Session session = Session.getInstance(props, null);
    Store store = session.getStore("imap");
    store.connect(_server, _username, _password);
    setStore(store);

    setRootFolders(FolderData.toFolderData(this, store.getDefaultFolder().list()));

    // TODO: Add logged in indicator to restrict access

    _gotoFolder(null);

    // Set up the user's preferences;  in a real app, these would
    // be persisted somewhere.
    PreferencesData preferences = new PreferencesData();
    setPreferences(preferences);
  }
  // catch all exceptions and report them as errors
  catch (Exception e)
  {
    FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                 e.getMessage(), null);

    FacesContext context = FacesContext.getCurrentInstance();
  context.addMessage(null, errorMessage);

    return null;
  }

  return "success";
}
 
Example 11
Project: alfresco-remote-api   File: FacesImageResolver.java   View Source Code Vote up 5 votes
@Override
public String resolveImagePathForName(String filename, FileTypeImageSize size)
{
    if (FacesContext.getCurrentInstance() != null)
    {
        return FileTypeImageUtils.getFileTypeImage(FacesContext.getCurrentInstance(), filename, size);
    }
    else
    {
        return null;
    }
}
 
Example 12
Project: myfaces-trinidad   File: TokenCacheDebugUtils.java   View Source Code Vote up 5 votes
/**
 * Generate a string showing the token and the view id we have saved for that token
 * 
 * This method should only be called when debugTokenCache() is true
 */
public static String getTokenToViewIdString(String token)
{      
  if (!_DEBUG_TOKEN_CACHE)
    throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
  FacesContext context = FacesContext.getCurrentInstance();
  return _getTokenToViewIdString( _getTokenToViewIdMap(context), token);
}
 
Example 13
Project: NICON   File: ContaBancoBean.java   View Source Code Vote up 5 votes
public void pesquisaCB(){
    FacesContext facesContext = FacesContext.getCurrentInstance();
    pesquisaConta = facesContext.getExternalContext().getRequestParameterMap().get("pesq");
    listContaBanco = new ContaBancoDao().resultPesqu(pesquisaConta, false, null);
    Validacao.atualizar("accountTableForm", "tableCantaBanco");
    RequestContext.getCurrentInstance().execute("$('.modalProcess').hide()");
}
 
Example 14
Project: oscm   File: JSFUtils.java   View Source Code Vote up 5 votes
/**
 * Verifies that the view locale is equal to the user's locale
 * 
 */
public static void verifyViewLocale() {
    FacesContext fc = FacesContext.getCurrentInstance();

    HttpServletRequest request = (HttpServletRequest) fc
            .getExternalContext().getRequest();
    HttpSession session = request.getSession();
    String localeString = null;
    if (session != null) {
        localeString = (String) session.getAttribute("loggedInUserLocale");
    }

    // if the view locale differs from the users locale change the view
    // locale
    Locale locale = fc.getViewRoot().getLocale();
    if (localeString != null && !locale.toString().equals(localeString)) {
        Iterator<Locale> it = fc.getApplication().getSupportedLocales();
        while (it.hasNext()) {
            locale = it.next();
            if (locale.toString().equals(localeString)) {
                fc.getViewRoot().setLocale(locale);
                return;
            }
        }
        // we use the default locale if the requested locale was not
        // found
        if (!fc.getViewRoot().getLocale()
                .equals(fc.getApplication().getDefaultLocale())) {
            fc.getViewRoot().setLocale(
                    fc.getApplication().getDefaultLocale());
        }
    }
}
 
Example 15
Project: chr-krenn-fhj-ws2017-sd17-pse   File: AdminDataBean.java   View Source Code Vote up 4 votes
@PostConstruct
public void init() {
    context = FacesContext.getCurrentInstance();

    /**
     * FG Info Flash: We need flash to make the param survive one redirect request
     * otherwise param will be null
     **/
    flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
    //Get UserId of user, who owns session
    Map<String, Object> session = context.getExternalContext().getSessionMap();


    id = context.getExternalContext().getRequestParameterMap().get("userid");

    flash.put("uid", id);


    String userProfId = String.valueOf(context.getExternalContext().getFlash().get("uid"));


    LOG.info("userProfId: " + userProfId);

    if (session.size() != 0 && session.get("user") != null) {

        userId = (int) session.get("user");
        LOG.info("SESSIOn UID: " + userId);
    } else {
        try {
            context.getExternalContext().redirect("/pse/login.xhtml");
        } catch (IOException e) {
            LOG.error("Can't redirect to /pse/login.xhtml");

        }
    }
    requestedCommunityList = new ArrayList<>();
    approvedCommunityList = new ArrayList<>();

    requestedCommunityList = service.getPending();
    LOG.info("Size of Requested Comm: " + requestedCommunityList.size());

    approvedCommunityList = service.getApproved();
    LOG.info("Size of Requested Comm: " + approvedCommunityList.size());
}
 
Example 16
Project: oscm   File: UiDelegate.java   View Source Code Vote up 4 votes
public FacesContext getFacesContext() {
    return FacesContext.getCurrentInstance();
}
 
Example 17
Project: ctsms   File: Messages.java   View Source Code Vote up 4 votes
public static void addLocalizedMessageId(String id, FacesMessage.Severity severity, String l10nKey, Object... args) {
	FacesContext context = FacesContext.getCurrentInstance();
	addMessageId(context, id, severity, CommonUtil.getMessage(l10nKey, args, getMessageResourceBundle(context), DEFAULT_FACES_MESSAGE));
}
 
Example 18
Project: oscm   File: ApplicationBean.java   View Source Code Vote up 4 votes
protected FacesContext getFacesContext() {
    return FacesContext.getCurrentInstance();
}
 
Example 19
Project: oscm   File: ManagedBeans.java   View Source Code Vote up 4 votes
public FacesContext getContext() {
    return FacesContext.getCurrentInstance();
}
 
Example 20
Project: ctsms   File: Messages.java   View Source Code Vote up 4 votes
public static void addMessageId(String id, FacesMessage.Severity severity, String message) {
	FacesContext context = FacesContext.getCurrentInstance();
	addMessageId(context, id, severity, message);
}