How to recover only the parameter of a url through a bean Managed

Asked

Viewed 426 times

1

I wanted to know how to recover only the parameter of this url in a bean Managed

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

Follow my bean Managed:

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 the string code is receiving only the url without parameter, and the Strings passwordEmpresa, seuParametro, youParametro2 receive null, how to receive the parameter, I could not receive it at all. PS: there is no xhtml for this Mb and to create the parameter I used redirect

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.