How to retrieve only the parameter of a url through a managed bean

1

I wanted to know how to retrieve only the parameter from this url in a managed bean

http://localhost:8180/blabla/teste.xhtml?codigoEmpresa=754

Follow my managed bean:

package br.com.sipag.web.sipagpremios.mb;


import java.io.Serializable;


import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

@Named
@RequestScoped
public class CampoOcultoBean implements Serializable {  



private static final long serialVersionUID = 1135497040977905291L;


//Construtor
public CampoOcultoBean(){   
}

@PostConstruct 
public boolean buscarEmpresaPelaUrl() throws Exception {
    String codigo =((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRequestURI();  
    String codigoEmpresa =  FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("codigoEmpresa");
    FacesContext fContext = FacesContext.getCurrentInstance();    
    ExternalContext extContext = fContext.getExternalContext();  
    HttpServletRequest request = (HttpServletRequest) fContext.getExternalContext().getRequest();  
    String seuParametro = request.getParameter("codigoEmpresa");
    String seuParametro2 = (String) request.getServletContext().getAttribute("codigoEmpresa");
    if(Long.valueOf(codigo) == 757)
        return true;
    return false;

    }

    }

The way code string is receiving only the url without parameter, and the Strings Company code, itsParametro, itsParametro2 are null, like receiving the parameter, I could not receive it at all. PS: there is no xhtml for this mb and to create the usei redirect

    
asked by anonymous 23.02.2017 / 23:06

0 answers