FacesContext.getExternalContext (). getRequestHeaderMap (); error mark

0

I'm trying to get a parameter of the URL with

FacesContext.getExternalContext().getRequestHeaderMap();

But in that part of the code I get the following error:

non static method cannot be referenced from a static context

What would be the correct way to use that function? o Is there a better way to obtain parameters of the URL in JSF (JavaServer Faces)?.

    
asked by gibran alexis moreno zuñiga 24.02.2017 в 23:16
source

1 answer

1

This is a way to get the parameters of the URL

link

Parameter parameterId = value 100.

1.- You must add the tag <f:viewParam> within <f:metadata> example:

<f:metadata>
  <f:viewParam name="parametroId" value="#{manageBean.parametroId}" />
</f:metadata>

The manageBean.parameterId attribute stores the value obtained by URL.

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head></h:head>
<f:metadata>
  <f:viewParam name="parametroId" value="#{manageBean.parametroId}"/>
</f:metadata>
<body>
 //Cuerpo...
</body>
</html>

And from a ManageBean accessing the context of the application would be as follows:

FacesContext facesContext = FacesContext. getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Map params = externalContext.getRequestParameterMap();
Integer almacenaParametroObtenido = new Integer((String) params.get("parametroId" ));
    
answered by 25.02.2017 / 00:02
source