I want to keep selected values after form validation. My code is here:
<h:form id="advanceSearchForm">
<p:dataGrid value="#{advancedSearchBean.selectedCriteriasList}" id="advancedSearchGrid" var="criteria" rowIndexVar="rowIndex"
columns="2" layout="grid" paginator="false" >
<h:panelGrid columns="1" id="criteriaPanel">
<p:panel id="criteria">
<div>
<!-- select criteria -->
<p:selectOneMenu value="#{criteria}" label="#{criteria.name}"
valueChangeListener="#{advancedSearchBean.addNewCriteria}"
converter="#{advancedSearchBean.criteriaConverter}">
<f:selectItems value="#{advancedSearchBean.criterias}"
var="crt"
itemLabel="#{crt.name}"
itemValue="#{crt}"
itemDisabled="#{advancedSearchBean.disableItem(crt.id)}" />
<f:ajax execute="#this"/>
</p:selectOneMenu>
<!-- launch date -->
<p:outputPanel rendered="#{criteria.id != null and (criteria.id == BusinessConstants.ADVANCED_SEARCH_FILTER_LAUNCH_DATE_ID)}">
<p:outputPanel>
<h:outputText value="From" styleClass="passportLabel" />
<p:inputMask required="true" id="launchStartDate" value="#{advancedSearchBean.launchStartDate}" mask="99/9999">
<f:convertDateTime pattern="MM/yyyy" timeZone="#{sessionScope.identity.timezone}" />
<p:ajax event="change" listener="#{advancedSearchBean.changeLaunchStartDate()}" />
</p:inputMask>
</p:outputPanel>
<p:outputPanel>
<h:outputText value="To" styleClass="passportLabel" />
<p:inputMask required="true" id="launchEndDate" value="#{advancedSearchBean.launchEndDate}" mask="99/9999">
<f:convertDateTime pattern="MM/yyyy" timeZone="#{sessionScope.identity.timezone}" />
<p:ajax event="change" listener="#{advancedSearchBean.changeLaunchEndDate()}" />
</p:inputMask>
</p:outputPanel>
</p:outputPanel>
</div>
</p:panel>
</h:panelGrid>
</p:dataGrid>
<!-- run search button -->
<div>
<p:commandButton id="runAdvancedSearch" value="Run search" action="#{advancedSearchBean.doAdvancedSearch}"
update="advanceSearchForm:advancedSearchGrid"/>
</div>
</h:form>
When i'm typing a wrong date and click on the Search button, i'm getting my validation error message, and i'm also losing the selected value in the selectOneMenu.
The strange thing is that if redirect to another page and after that i'm coming back, it works... My bean is:
#ManagedBean(name = "advancedSearchBean")
#ViewScoped
public class AdvancedSearchBean {
private Map<Long, String> criteriaMap;
private List<AutocompleteCriteria> criterias;
private List<AutocompleteCriteria> selectedCriteriasList;
#PostConstruct
public void init() {
criteriaMap = BusinessConstants.ADVANCED_SEARCH_CRITERIA.entrySet().stream().sorted(Entry.comparingByValue()).
collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
criterias = new ArrayList<AutocompleteCriteria>();
for(Iterator<Map.Entry<Long, String>>it = criteriaMap.entrySet().iterator();it.hasNext();){
Map.Entry<Long, String> entry = it.next();
criterias.add(new AutocompleteCriteria(entry.getKey(), entry.getValue()));
}
criteriaConverter = new AutocompleteConverter(criterias);
selectedCriteriasList = new ArrayList<AutocompleteCriteria>();
selectedCriteriasList.add(new AutocompleteCriteria(BusinessConstants.ADVANCED_SEARCH_FILTER_NO_CRITERIA, criteriaMap.get(BusinessConstants.ADVANCED_SEARCH_FILTER_NO_CRITERIA)));
}
In your p:selectOneMenu You have value="#{criteria}" instead of value="#{advancedSearchBean.criteria}".
Related
I have a command Button that calls a method from the Session Scoped Bean if the inputs are valid.
<h:form id="mainform">
<p:panel id="panelform" header="Email Extractor" >
<h:panelGrid id="formulaire" columns="2">
<h:panelGroup id="formblock" layout="block" >
<p:panelGrid columns="2">
<p:outputLabel for="Keyword" value="Keyword: " />
<p:inputText id="Keyword" type="search" requiredMessage="Keyword is required"
value="#{mailMB.keyword}" required="true" label="Keyword">
</p:inputText>
<p:outputLabel for="Emailsnbr" value="Enter the emails'number:" />
<p:inputText id="Emailsnbr" type="number" requiredMessage="Emails number is required" validatorMessage="Enter a number"
value="#{mailMB.number}" required="true" label="Emailsnbr">
<f:validateDoubleRange minimum="1" maximum="53500" />
</p:inputText>
</p:panelGrid>
</h:panelGroup>
</h:panelGrid>
<p:commandButton value="Extract" style="width: 12%;height: 100%" update="tableemails, :confirmPurchaseTest, :mainform" id="extractbutton" ajax="true" widgetVar="ButtonExtract"
actionListener="#{mailMB.searchEmails()}" onstart="blockUIWidget1.show();" oncomplete=" blockUIWidget1.hide(); if (args && !args.validationFailed) confirmDialog.show();" />
<p:dialog widgetVar="blockUIWidget1" modal="true" closable="false" resizable="false" >
<h:panelGrid columns="2">
<div>
<p:graphicImage url="pictures/loading81.gif" width="200" height="200" alt="animated-loading-bar"/>
<h:outputLabel value="Please wait..."/>
</div>
<div>
<p:button outcome="home" icon="ui-icon-arrowthick-1-w" title="Back To Home" style="margin-right: 5px;white-space: nowrap" />
</div>
</h:panelGrid>
</p:dialog>
</p:panel>
<p:dataTable rowIndexVar="rowIndex" id="tableemails" value="#{mailMB.mails}" var="item" rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginator="true" rows="5" styleClass="case-table" emptyMessage="No records found with given criteria" paginatorPosition="bottom"
filteredValue="#{mailMB.filteredMails}" rowKey="#{item.id}"
selection="#{mailMB.selectedMail}" selectionMode="single" >
<p:ajax event="rowSelect" update=":mainform"/>
<p:column styleClass="blockable">
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
</p:dataTable>
</h:form>
<p:confirmDialog closable="false" style="position: absolute; width: 50px; border-color: blue" id="confirmPurchaseTest" message="Your Database was successfully created. It contains #{mailMB.number} Emails "
appendToBody="true"
header="Get Emails List" severity="info" widgetVar="confirmDialog">
<h:form>
<p:commandButton id="getEmails" style="width: 35%;height: 100%" value="Get Emails" oncomplete="window.location.href = '/Hitonclick/emailsList.xhtml'" >
<f:event type="preRenderView" listener="#{mailMB.preRender}"/>
</p:commandButton>
<p:commandButton id="declineTest" style="width: 35%;height: 100%" value="Decline" onclick="deleteDialog.show();" />
</h:form>
</p:confirmDialog>
My SessionScoped Bean is
#ManagedBean(name = "mailMB")
#SessionScoped
public class MailManagedBean implements Serializable {
#Inject
private MailBusinessLocal mailmanagerLocal;
#Inject
private DataBusinessLocal dataBusinessLocal;
#Inject
private CustomerBusinessLocal customerBusinessLocal;
.....
#PostConstruct
public void init() {
mails = new ArrayList<>();
}
public void searchEmails() throws Exception {
idCustomer = (String) session.getAttribute("idCustomer");
System.out.println(idCustomer + " this is it");
Customer customer = customerBusinessLocal.findById(idCustomer);
data = dataBusinessLocal.createData(new Date(), number, keyword, moteur, customer, State.REJECTED);
mails = mailBusinessLocal.createEmails(keyword, number, moteur, data);
System.out.println("Method was invoked");
}
}
if i enter 0 in the emails's number input for exemple and submit with Extract command Button for the first time i get the validatorMessage So i enter a valid number and submit again. And here comes the problem, the dialog in the oncomplete is shown without invoking the method in the actionListener. I mean i get the confirm dialog of persisted object without invoking the method that persists the object. Am i missing something??
How could i fix that?
I am trying to recharge the same primefaces component after an successful login with ajax behaviour, but I don't know how to do this. The recharged component must show the complete name of the user which is recovered by an hibernate dao from the DB and the input boxes for user and password must desappear.
View :
<h:head>
<title>header layout</title>
</h:head>
<h:body>
<h:panelGrid id="loginPanelGrid">
<h:form id="loginForm">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginManagedBean.username}" id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<p:password value="#{loginManagedBean.password}" id="password" required="true" label="password" />
</h:form>
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login" update="okLoginPanelGrid" action="#{loginManagedBean.login(actionEvent)}"/>
</f:facet>
</h:panelGrid>
<p:panelGrid id="okLoginPanelGrid">
<h:outputText id="clienteLogado" value="#{loginManagedBean.loggedClient}" />
</p:panelGrid>
</h:body>
Bean :
#ManagedBean
#SessionScoped
public class LoginManagedBean implements Serializable{
private String username;
private String password;
private Cliente loggedClient;
#ManagedProperty(value="#{clienteDAO}")
private ClienteDAO clienteDAO;
public void login(ActionEvent actionEvent){
RequestContext context = RequestContext.getCurrentInstance();
if( (this.getUsername() != null && !this.getUsername().isEmpty()) &&
(this.getPassword() != null && !this.getPassword().isEmpty()) ){
List<Cliente> clienteLogin = clienteDAO.comprobarLogin(username, password);
if(clienteLogin != null && clienteLogin.size() > 0){
loggedClient = new Cliente();
for(Cliente client : clienteLogin){
loggedClient.setCliente_nombre(client.getCliente_nombre());
loggedClient.setCliente_apellido1(client.getCliente_apellido1());
loggedClient.setCliente_apellido2(client.getCliente_apellido2());
}
}else{
System.out.println("**** There are NO CLIENTS for this user and password selected ****");
}
}else{
System.out.println("**** user or password NOT RECOVERED ****");
}
}
You should move your h:form to encapsulate the p:commandButton. That prevent your p:commandButton to submit anything to the bean. You should add it like this :
<h:body>
<h:panelGrid id="login-panel">
<h:form rendered="#{loginManagedBean.loggedClient eq null}">
<h:panelGroup id="loginPanelGrid">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginManagedBean.username}" id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<p:password value="#{loginManagedBean.password}" id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login" update="login-panel" action="#{loginManagedBean.login(actionEvent)}"/>
</f:facet>
</h:panelGroup>
</h:form>
<p:panelGroup rendered="#{loginManagedBean.loggedClient ne null}" id="okLoginPanelGrid">
<h:outputText id="clienteLogado" value="#{loginManagedBean.loggedClient.client_name}" />
</p:panelGroup>
</h:panelGrid>
</h:body>
Not related :
I would also say the shorter a bean lives, the better your memory usage will be. In that way, the bean LoginManagedBean don't need to be SessionScoped, it could even be only RequestScoped if you move your property loggedClient to a SessionScoped attribute.
i have a behaviour here i don't understand. I am using Spring 3.1, Primefaces 3.3.1 and JSF 2.
I am using a datatable and want to add a row via a dialog within a form.
This is my table, including the button to call the dialog:
<h:form id="form">
<!-- open the dialog on click -->
<p:commandButton value="New" onclick="dlgAddTask.show()"
update="taskList" />
<p:dataTable var="task" value="#{taskBean.tasks}" id="taskList"
widgetVar="taskList" editable="true" rowkey="task.id"
paginator="true" rows="50"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100">
<p:ajax event="rowEdit" update="#this" listener="#{taskBean.save}" />
<p:column headerText="Name" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{task.name}" style="width:100%" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{task.name}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:20px">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
This is my dialog with the relevant javascript (it's in the same form as the table is):
<p:dialog id="dlgAddTask" header="Add New Task" widgetVar="dlgAddTask">
<h:form>
<h:panelGrid columns="2" cellpadding="5" width="500">
<h:outputLabel for="name" value="Name" />
<p:inputText value="#{addTaskBean.name}" id="name" required="true"
label="name" />
<h:outputLabel for="description" value="Description:" />
<p:inputTextarea value="#{addTaskBean.description}"
id="description" label="description" />
<h:outputLabel for="dueTo" value="Due To:" />
<p:calendar value="#{addTaskBean.dueTo}" id="dueTo" label="dueTo" />
<h:outputLabel for="done" value="Done:" />
<p:selectBooleanCheckbox value="#{addTaskBean.done}" id="done"
label="done" />
<f:facet name="footer">
<p:commandButton id="addButton" value="Add"
actionListener="#{addTaskBean.addTask}"
oncomplete="handleLoginRequest(xhr, status, args)" />
<p:commandButton value="Cancel" onclick="dlgAddButton.hide()" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<script type="text/javascript">
function handleLoginRequest(xhr, status, args) {
if (args.validationFailed || !args.taskAdded) {
jQuery('#dialog').effect("shake", {
times : 3
}, 100);
} else {
dlgAddTask.hide();
}
}
</script>
</h:form>
And this is my Bean (leaving out the getter and setter):
public class AddTaskBean {
#Inject
TaskDao taskDao;
private boolean done;
private String name;
private String description;
private Date dueTo;
#Transactional
public void addTask() {
RequestContext context = RequestContext.getCurrentInstance();
FacesMessage msg = null;
Task task = new Task();
boolean taskAdded = false;
task.setDescription(getDescription());
task.setDone(isDone());
task.setDueTo(getDueTo());
task.setName(getName());
if (taskDao.persist(task) != null) {
taskAdded = true;
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Task",
getName() + " added.");
} else {
taskAdded = false;
msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Task Error",
"Something went wrong on adding task.");
}
FacesContext.getCurrentInstance().addMessage(null, msg);
context.addCallbackParam("taskAdded", taskAdded);
}
Now, if i open the dialog, add a task, it works up to the update point. So i have a new task in the database, the dialog closes, but the table does not get updated.
Hitting F5 shows me the new task in the table.
But (please read carefully as it is a bit tricky to explain for me), if i dont close the dialog after adding a task (by not calling the javascript via oncomplete="handleLoginRequest(xhr, status, args)"), the task will be added too, but the dialog remains open of course.
If i press cancel then, the dialog closes and the table get's updated and i can see the new task.
I cannot explain this, maybe one of you can?
Thanks in Advance
I have a primefaces dialog in which I can create or update an Employee.
It will open by this
</p:dialog><p:dialog id="employeeEditDialog" header="#{msg.employeeEdit}"
widgetVar="dlgEmployeeEdit" resizable="false">
<p:ajax event="close" listener="#{employeeView.cancel}"
update=":showEmployees:liste" />
<ui:include src="/content/Employee/ShowEmployeeContent.xhtml" />
</p:dialog>
And here is the Dialog Page
<h:form id="editContent">
<p:growl id="growl" showDetail="true" sticky="false" life="5000" />
<p:focus id="focusEdit" for="emSalutation" />
<h:panelGrid columns="2" id="contentGrid">
<h:panelGrid columns="2" id="allgemein"> <h:outputText value="#{msg.id}" />
<h:outputText value="#{employeeView.newEmployee.id}" />
<h:outputText value="#{msg.salutation}" />
<p:selectOneMenu value="#{employeeView.newEmployee.salutation}"
id="emSalutation">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{employeeView.salutations}" var="salutations"
itemLabel="#{salutations.description}" itemValue="#{salutations}" />
</p:selectOneMenu>
<h:outputText value="#{msg.title}" />
<p:inputText value="#{employeeView.newEmployee.title}" id="emTitle" />
<h:outputText value="#{msg.name}" />
<p:inputText value="#{employeeView.newEmployee.name}" id="emName"
validatorMessage="#{msg.valName}" />
<h:outputText value="#{msg.prename}" />
<p:inputText value="#{employeeView.newEmployee.prename}"
id="emPrename" />
<h:outputText value="#{msg.loginname}" />
<p:inputText value="#{employeeView.newEmployee.loginname}"
validatorMessage="#{msg.valLogin}" />
<h:outputText value="#{msg.department}" />
<h:panelGrid columns="2" id="departmentGrid">
<p:selectOneMenu value="#{employeeView.selectedDepartment.id}"
id="emDepartment">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{employeeView.departmentList}"
var="department" itemLabel="#{department.description}"
itemValue="#{department.id}" />
</p:selectOneMenu>
<p:commandButton icon="ui-icon-disk" immediate="true"
oncomplete="dlgDepartmentAdd.show()"
update="departmentGrid, :departmentAddDialog">
</p:commandButton>
</h:panelGrid>
<h:outputText value="#{msg.position}" />
<h:panelGrid columns="2" id="positionGrid">
<p:selectOneMenu value="#{employeeView.selectedPosition.id}"
id="emPosition">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{employeeView.positionList}" var="position"
itemLabel="#{position.description}" itemValue="#{position.id}" />
</p:selectOneMenu>
<p:commandButton icon="ui-icon-disk" immediate="true" id="buttonPos"
oncomplete="dlgPositionAdd.show()"
update="positionGrid, :positionAddDialog">
</p:commandButton>
</h:panelGrid>
<h:outputText value="#{msg.phone}" />
<p:inputText value="#{employeeView.newEmployee.phone}" id="emPhone" />
<h:outputText value="#{msg.fax}" />
<p:inputText value="#{employeeView.newEmployee.fax}" id="emFax" />
<h:outputText value="#{msg.email}" />
<p:inputText value="#{employeeView.newEmployee.email}" id="emEmail"
validator="myEmailValidator" validatorMessage="#{msg.valEmail}" />
<h:outputText value="#{msg.employeedSince}" />
<p:calendar value="#{employeeView.newEmployee.employeedSince}"
id="emEmployeedSince" pattern="dd.MM.yyy" showOn="button" />
<h:outputText value="#{msg.employeedEnd}" />
<p:calendar value="#{employeeView.newEmployee.employeedEnd}"
id="emEmployeedEnd" pattern="dd.MM.yyy" showOn="button" />
<h:outputText value="#{msg.active}" />
<p:selectBooleanCheckbox value="#{employeeView.newEmployee.active}"
id="emActive" />
</h:panelGrid>
</h:panelGrid>
<h:panelGrid columns="3" class="buttonContent" id="button">
<p:commandButton value="#{msg.save}" id="saveButton" update="growl"
oncomplete="if ((!args.validationFailed)) dlgEmployeeEdit.hide()"
actionListener="#{employeeView.saveOrUpdateEmployee}" />
<p:commandButton value="#{msg.cancel}" immediate="true"
oncomplete="dlgEmployeeEdit.hide()"/>
<p:commandButton value="#{msg.delete}" immediate="true"
oncomplete="dlgEmployeeDelete.show()"
disabled="#{(employeeView.newEmployee.id == null) ? true : false}" />
</h:panelGrid>
<p:defaultCommand target="saveButton" /></h:form></html>
And now here are the two Methods which used in the Page:
/**
* Methode zum Speichern und Updaten eines Mitarbeiters
*/
public void saveOrUpdateEmployee() {
FacesContext context = FacesContext.getCurrentInstance();
try {
logger.debug("save aufgerufen " + this.newEmployee);
if (this.selectedDepartment.getId() == null) {
this.newEmployee.setDepartment(null);
}
else {
this.newEmployee.setDepartment(this.departmentHandler.getDepartmentById(this.selectedDepartment.getId()));
}
if (this.selectedPosition.getId() == null) {
this.newEmployee.setPosition(null);
}
else {
this.newEmployee.setPosition(this.positionHandler.getPositionById(this.selectedPosition.getId()));
}
this.employeeController.saveOrUpdate(this.newEmployee);
logger.info("Mitarbeiter erfolgreich gespeichert");
context.addMessage(null, new FacesMessage("Successful", "Mitarbeiter gespeichert "));
}
catch (Exception e) {
logger.error("Fehler beim Speichern des Mitarbeiters", e);
context.addMessage(null, new FacesMessage("Fehler beim Speichern des Mitarbeiters", e.getMessage()));
}
this.loadPersons();
}
/**
* Methode zum Abbrechen bei der Neuanlage/Ă„nderung eines Mitarbeiters
* Felder leeren
*/
public void cancel() {
logger.debug("cancel()");
this.newEmployee = new Employee();
this.selected = new Employee();
this.selectedDepartment = new Department();
this.selectedPosition = new Position();
}
If now, validation failed, the dialog will not hide. This is OK and desired. It shows my created message via FacesMassages as required. If I then close the dialogbox by myself with the "cancel"-Button, dialog will close as expected. In the cancel()-method the object Employee will be set to a new instance of Employee (this.newEmployee = new Employee()) as you can see. But when I open the dialog after validation failure, the object "newEmployee" contains just the old values... Why does my method cancel()not work? I don't understand.
This problem is related to JSF issue 1060 and in detail elaborated in this Q&A: How can I populate a text field using PrimeFaces AJAX after validation errors occur?
To the point, this behaviour is (unfortunately) correct as per current JSF specification and this can be solved as follows: during the invoke action phase you need to collect UIInput components which are included in the ajax render, but not in the ajax execute, and then invoke resetValue() method on them. This can be in a generic and reuseable fashion be done with help of OmniFaces ResetInputAjaxActionListener.
I am trying to update the google map of PrimeFaces with the new latitude, longitude with the help of p:ajax, but it is not working...I'm using JSF 2.0. I have used p:ajax earlier in the similar way and it worked beautifully. Any idea why this does not work? The following is the code, contForm is the id of the form.
<h:outputText value="Latitude :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapLatitude}" size="10">
<p:ajax event="blur" update="contForm:gMapID"/>
</h:inputText>
<h:outputText value=" Longitude :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapLongitude}" size="10" >
<p:ajax event="blur" update="contForm:gMapID"/>
</h:inputText>
<h:outputText value=" Marker :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapMarker}" size="20" >
<p:ajax event="blur" update="contForm:gMapID"
listener="#{confirmBrandRegistration.updateMarker}"/>
</h:inputText>
</h:panelGrid>
<p:outputPanel id="gMapID">
<f:view contentType="text/html">
<p:gmap center="#{confirmBrandRegistration.newBrand.mapLatitude}, #{confirmBrandRegistration.newBrand.mapLongitude}"
zoom="16" type="HYBRID" streetView="true"
model="#{confirmBrandRegistration.simpleModel}"
style="width:500px;height:400px" />
</f:view>
</p:outputPanel>
I solved it right now:)
index page:
<h:panelGroup id="pmap">
<p:inputText value="#{mapManager.address}" label="Adresa" />
<h:outputText value="#{mapManager.geo}" id="m" />
<p:commandButton value="OK" actionListener="#{mapManager.updateMapCenter(ae)}" update="pmap" />
<p:gmap center="#{mapManager.geo}"
zoom="7"
type="HYBRID"
style="width:800px;height:400px"
streetView="true"
model="#{mapManager.map}"
overlaySelectListener="#{mapBean.onMarkerSelect}"
>
<p:gmapInfoWindow>
<p:outputPanel style="text-align:center; display:block; margin:auto:">
<h:outputText value="#{mapManager.marker.title}" />
wserw
</p:outputPanel>
</p:gmapInfoWindow>
</p:gmap>
</h:panelGroup>
part of managed bean:
private MapModel map;
private Marker marker;
private String address;
private String geo="49.817491999999992, 15.4729620";
public MapManager() {
}
#PostConstruct
public void init() {
events = edao.findAll();
map = new DefaultMapModel();
for (Event event : events) {
Marker m=new Marker(new LatLng(event.getLat(), event.getLng()), event.getName());
map.addOverlay(m);
}
}
public void updateMapCenter(ActionEvent ae) {
GMapService gs=new GMapService();
LatLng geo=gs.getGeocode(address);
this.geo=geo.getLat()+","+geo.getLng();
}
hope it solved your problem.