I am making a search by id and in my home page I have an inputText and a commandButton. When I click the commandButton, it has to set the id with the number passed in the inputText and redirect me to the map page to track coordinates referring to this id. As I have to access the ManagedBean to set the Id variable, I have to redirect to the map page through a method which returns a String with the "outcome" of the page address. The problem is that the map is not rendering when the page is loaded. If the map page is accessed normally, without the outcome coming from the bean, the map loads correctly, then its not API key problem or wrong coordinates. Does anyone know what is happening or know any other solution?
Home page:
<ui:composition template="/WEB-INF/template/LayoutPadrao.xhtml"
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"
xmlns:p="http://primefaces.org/ui">
<ui:define name="titulo">Dashboard</ui:define>
<ui:define name="corpo">
<h:form>
<p:panel
style="margin-top:0px;margin-left:450px;width:480px;border: none !important;">
<p:panelGrid id="grid2" columns="2" styleClass="semBorda">
<p:inputText id="pesquisarGado" size="50" style="height:25px;"
value="#{gadoBean.gadoBeanM.name}" required="true"
requiredMessage="Digite o código do gado" />
<p:commandButton action="#{gadoBean.outcome()}"/>
<p:button outcome="gado/rastrearGado"/>
<p:message for="pesquisarGado" display="icon" />
</p:panelGrid>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
ManagedBean:
@Named
@SessionScoped
//attributes and other methods
public String outcome() {
return "gado/rastrearGado";
}
public void inicializar() {
GravarPosicao();//method to record coo in the DB
obterPosicaoPeloId();
}
public void obterPosicaoPeloId() {
mapa = new DefaultMapModel();
tagsCadastradas = new ArrayList<Tag>();
tagsCadastradas = tagsRep.listarTag();
this.getTagsCadastradas().size();
posicoes = new ArrayList<Coordenadas>();
ultimasPosicoes = new ArrayList<Coordenadas>();
String id = this.getGadoBeanM().getName();
cooPorId = coordenadasRep.listarCoords(Long.parseLong(id));
System.out.println("posicoes: " + cooPorId.getPosData());
System.out.println("id: " + id);
coord = new LatLng(cooPorId.getPosLatitude(), cooPorId.getPosLongitude());
mapa.addOverlay(new Marker(coord, "Gado"));
lastLong = (float) cooPorId.getPosLongitude();
lastLat = (float) cooPorId.getPosLatitude();
center = lastLat + "," + lastLong;
System.out.println(center);
}
Map page:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f ="http://java.sun.com/jsf/core" xmlns:o="http://omnifaces.org/ui">
<h:head>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDeF32jO4j5mAORJTcNICT3o8Nz8G0QZIg"
type="text/javascript"></script>
</h:head>
<title>Rastreamento</title>
<f:metadata>
<f:event listener="#{gadoBean.inicializar}" type="preRenderView" update="@form"/>
</f:metadata>
<h:body>
<h:form>
<p:panel id="panelMap" style="margin-top:100px;margin-left:410px;width:508px;">
<p:gmap id="mapa"
center="#{gadoBean.center}"
zoom="9"
model="#{gadoBean.mapa}"
type="HYBRID"
style="width:600px;height:400px"/>
</p:panel>
</h:form>
</h:body>
</html>