Is there any possibility to change the interval-steps while using Primefaces timeline custom - primefaces

Is it somehow possible to set an interval for the event-object (rangechange event)?
This behaviour is shown on their website/showcase.
I know that it depends on the zoom level, but I'd like to set the interval to 15min-steps.

You can use "<p:poll"
here is an example from primefaces website
xhtml:
<div class="card">
<h:form>
<h1 class="p-text-center">
<h:outputText id="txt_count" value="#{pollView.number}"/>
</h1>
<p:poll interval="2" listener="#{pollView.increment}" update="txt_count"/>
</h:form>
</div>
bean:
#Named
#ViewScoped
public class PollView implements Serializable {
private int number;
public void increment() {
number++;
}
public int getNumber() {
return number;
}
}

Related

New markers are not shown in PrimeFaces gmap (JSF 2.2)

I'm using PrimeFaces 8.0.3. The first time the page loads, the gmap has no markers because the table where I store the coordinates is empty. When a new marker is added, the page refreshes but the map still doesn't show the marker. This problem only happens when I run the application on the server, because when I run it locally, the new marker is shown without problems. The page refreshes every ten seconds to check if there are new rows in the table.
Html:
<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=[provided api key]"></script>
<h:form>
<p:panel>
<p:gmap center="-0.2727324,-78.5489364" zoom="18" type="ROADMAP" style="width:90%;height:700px" model="#{mapaCtrl.simpleModel}" />
<p:poll interval="10" listener="#{contadorCtrl.recargarMapa()}" />
</p:panel>
</h:form>
MapaCtrl:
#ManagedBean
#RequestScoped
public class MapaCtrl implements Serializable
{
private MapModel simpleModel;
...
public void dibujarMarcadores()
{
for(int i = 0; i < listaSolicitud.size(); i++)
{
LatLng coord = new LatLng(Double.parseDouble(listaSolicitud.get(i).getLatitud()), Double.parseDouble(listaSolicitud.get(i).getLongitud()));
simpleModel.addOverlay(new Marker(coord, listaSolicitud.get(i).getDescripcionsolicitud()));
}
}
}
ContadorCtrl:
#ManagedBean
#RequestScoped
public class MapaCtrl implements Serializable
{
...
public void recargarMapa()
{
...
if(solicitudesActuales != MapaCtrl.solicitudesIniciales)
{
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
try
{
ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
}
catch(IOException ex)
{
Logger.getLogger(ContadorCtrl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
How can I show the new markers in the map?
You need to assign an id to your map component, and then update it when polling:
<p:gmap id="myMap" center="-0.2727324,-78.5489364" zoom="18" type="ROADMAP" style="width:90%;height:700px" model="#{mapaCtrl.simpleModel}" />
<p:poll interval="10" listener="#{contadorCtrl.recargarMapa()}" update="myMap"/>

Passing an object from p:dataTable to Controller on rowSelect in JSF

I am trying to pass an object from populated with items table to Controller. Then I use JS alert to verify success. However I fail to pass anything from the table.
Any help would be appreciated.
issues.xhtml
<p:dataTable var="issue" value="#{issuesController.findWithParameter(issues, startenddates)}" styleClass="list" selectionMode="single" selection="#{issuesController.issue}" rowKey="#{issue.id}" >
<p:ajax event="rowSelect" update="mainForm" listener ="#{issuesController.onRowSelect}"
oncomplete="alert(args.name)"/>
<p:column headerText="Id" id = "head_id" style="width:0%; padding: 0px;">
<h:outputText value="#{issue.id}"/>
</p:column>
<p:column headerText="Child" id = "head_child" style="width:12%;">
<h:outputText value="#{issue.child}"/>
</p:column>
...
</p:dataTable>
IssuesController.java
#Named("issuesController")
#RequestScoped
public class IssuesController implements Serializable {
#Inject
private Issues issue;
....
public void onRowSelect(SelectEvent event) throws IOException {
Issues i = (Issues) event.getObject();
String toWrite;
if (i == null) {
toWrite = "Item is not recieved";
} else {
toWrite = i.toString();
}
RequestContext.getCurrentInstance().addCallbackParam("name", toWrite);
}
Issues.java
#Named("issues")
#SessionScoped
#XmlRootElement
public class Issues implements Serializable {
....
}
I tried different types of scope, tried f:attribute...neither of this worked...
Try using process="#this" and change the scope to
#ViewScoped.

How to send Data from selectManyCheckbox to bean?

i have a Java EE setup with JSF and primefaces and i'm trying to generate a selection, based on the chosen entry in a <selectOneMenu>.
My problem is that the selectManyCheckbox (or any other similar ui element) has all items filled in correctly and the items are selectable, but if a selection was made, the action of the commandButton doesn't get called.
I've set a breakpoint on the method. If I don't choose any item, the breakpoint gets hit, if I choose any amount of items greater than zero, the breakpoint doesn't get hit.
I read that one solution could be to define a converter. I tried that and if I set a breakpoint, it correctly converts the items, I chose, but nevertheless the method, defined as action, doesn't get called.
Btw: Sorry for german code, i'm a german and naming the methods and variables in german was set by guideline
The xhtml File:
<h:form>
<p:panelGrid columns="2">
<p:outputLabel for="kennzeichenInput">Kennzeichen: </p:outputLabel>
<p:inputText id="kennzeichenInput"></p:inputText>
<p:outputLabel for="studiengang">Studiengang: </p:outputLabel>
<p:selectOneMenu id="studiengang" value="#{registrationsController.gewaehlterStudiengang}">
<f:selectItem itemValue="#{null}" itemLabel="--Studiengang aussuchen--"/>
<f:selectItems value="#{registrationsController.getAlleStudiengaenge()}"/>
<p:ajax value="valueChange" update="vorlesungenInStudiengang" listener="#{registrationsController.onStudiengangGeaendert}"/>
</p:selectOneMenu>
</p:panelGrid>
<h:selectManyCheckbox id="vorlesungenInStudiengang"
value="#{registrationsController.gewaehlteVorlesungen}"
label="Vorlesungen" converter="de.phwt.parkhwt.domain.converter.vorlesung_converter">
<f:selectItems value="#{registrationsController.vorlesungen}"/>
</h:selectManyCheckbox >
<p:commandButton value="Registrieren" type="submit" action="#{registrationsController.registriereKennzeichen()}"/>
</h:form>
The Bean:
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.enterprise.context.RequestScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.inject.Inject;
import javax.inject.Named;
import de.phwt.parkhwt.domain.CollectionKonverter;
import de.phwt.parkhwt.domain.KennzeichenRepository;
import de.phwt.parkhwt.domain.Studiengang;
import de.phwt.parkhwt.domain.Vorlesung;
#RequestScoped
#Named
public class RegistrationsController
{
#Inject
private KennzeichenRepository repository;
private String gewaehlterStudiengang;
private List<Vorlesung> vorlesungen;
private List<Vorlesung> gewaehlteVorlesungen;
public String getGewaehlterStudiengang()
{
return gewaehlterStudiengang;
}
public void setGewaehlterStudiengang(String gewaehlterStudiengang)
{
this.gewaehlterStudiengang = gewaehlterStudiengang;
}
public List<Vorlesung> getVorlesungen()
{
return vorlesungen;
}
public void setVorlesungen(List<Vorlesung> vorlesungen)
{
this.vorlesungen = vorlesungen;
}
public Vorlesung getVorlesung(String name)
{
return this.repository.sucheVorlesung(name);
}
public List<Vorlesung> getGewaehlteVorlesungen()
{
return gewaehlteVorlesungen;
}
public void setGewaehlteVorlesungen(List<Vorlesung> gewählteVorlesungen)
{
this.gewaehlteVorlesungen = gewählteVorlesungen;
}
public Set<Studiengang> getAlleStudiengaenge()
{
return repository.getAlleStudiengaenge();
}
public List<Vorlesung> getVorlesungenDesStudiengangs(String gewaehlterStudiengang)
{
Studiengang studiengang = repository.sucheStudiengang(gewaehlterStudiengang);
return CollectionKonverter.toList(studiengang.getVorlesungen());
}
public String registriereKennzeichen()
{
return "";
}
public void onStudiengangGeaendert(AjaxBehaviorEvent event)
{
if (getGewaehlterStudiengang() != null)
{
setVorlesungen(getVorlesungenDesStudiengangs(getGewaehlterStudiengang()));
}
else
{
setVorlesungen(new ArrayList<Vorlesung>());
}
}
}
The Converter:
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
import de.phwt.parkhwt.controller.RegistrationsController;
#FacesConverter("de.phwt.parkhwt.domain.converter.vorlesung_converter")
public class VorlesungConverter implements Converter
{
#Inject
KennzeichenRepository repository;
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
ValueExpression vex =
context.getApplication()
.getExpressionFactory()
.createValueExpression(context.getELContext(),
"#{registrationsController}", RegistrationsController.class);
RegistrationsController reg = (RegistrationsController) vex.getValue(context.getELContext());
Vorlesung vorlesung = reg.getVorlesung(value);
return vorlesung;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
if (value.getClass() == new Vorlesung().getClass())
{
Vorlesung v = (Vorlesung) value;
return v.getName();
}
return null;
}
}
Thanks to Mike Balthasar for his comment!
The solution was to add ajax="false" to my commandButton.
For more information, see his comment.

collapse or expand p:accordionPanel programmatically

What I am trying to achieve is?
After Load Button Clicked, If any one of the textfield is set, So in result the "accordion panel" filter should expand.
After Load Button Clicked, If all text fields are not set, So in result the "accordion panel" filter should collapse.
I have gone through accordion panel primefaces documentation but could not found it helpful.
http://www.primefaces.org/docs/vdl/3.5/primefaces-p/accordionPanel.html
I have gone through previously asked question on stackoverflow, the answer to this question also could not satisfy me to achieve my required result.
Expanding Accordion Panel in PrimeFaces with a RadioButton click
ManagedBean
package com.pk.test;
import javax.faces.bean.ManagedBean;
#ManagedBean(name="testBean")
public class AccordionTestBean {
private String name;
private String semester;
private String age;
private Boolean checkNameTextField = false;
public void save(){
System.out.println("Close Filter If any one field of form is set");
System.out.println("Name: "+getName());
System.out.println("Age: "+getAge());
System.out.println("Semester: "+getSemester());
if(getName()!= null){
setCheckNameTextField(true);
//if name textfield is set to a value, on save click filter will not collapse or close
}
else
setCheckNameTextField(false);
//if name textfield is set to a value, on save click filter will collapse
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSemester() {
return semester;
}
public void setSemester(String semester) {
this.semester = semester;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public Boolean getCheckNameTextField() {
return checkNameTextField;
}
public void setCheckNameTextField(Boolean checkNameTextField) {
this.checkNameTextField = checkNameTextField;
}
}
FrontEnd File
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<body>
<h:form id="formId">
<p:accordionPanel id="accordion" cache="false" activeIndex="-1"
style="margin-bottom:20px;width:330px;" widgetVar="acc">
<p:ajax event="tabClose" listener="#{testBean.checkNameTextField}" />
<p:tab title="Filter:"
titleStyle="width:330px;background-color:#DAEDF4">
<h:panelGrid columns="2">
<h:outputLabel value="Name" />
<h:inputText value="#{testBean.name}" />
<h:outputLabel value="Age" />
<h:inputText value="#{testBean.age}" />
<h:outputLabel value="Semester" />
<h:inputText value="#{testBean.semester}" />
</h:panelGrid>
<p:commandButton icon="ui-icon-save" value="Save"
action="#{testBean.save}"
onclick="PF('formId:accordion').hide();" />
</p:tab>
</p:accordionPanel>
</h:form>
</body>
</html>
I did'n understand what you are trying to do, but to expand/colapse an accordion panel you can use this
expand: PF('accordian-widgetVar').select(index)
collapse: PF('accordian-widgetVar').unselect(index)
where accordian-widgetVar is the value of the property widgetVar of your accordionPanel and index is the index of the tab that you want to expand/collapse
also you can execute that from a bean like this
RequestContext.getCurrentInstance().execute("PF('accordian-widgetVar').unselect(index)");

Primefaces contextmenu refresh when click on row of treetable

the situation is the following: I've got a treeTable with 3 different type of objects. The table contains the p:ajax with event="select". I wrote 3 different contextMenus, one for each type... and all works well.
My problem is that I want to enable/disable some of the menuItems; to do that I use the attribute "rendered" with condition based on properties of selected node.
All works, but only the second time I right-click on the same object (the first time the contextMenu isn't filtered).
Here is the code... (I'm including only one type of object for semplicity)
treeTable page:
<h:form id="form" prependId="false">
<p:treeTable value="#{documentsController.root}" var="document" id="docs"
selectionMode="single" selection="#{documentsController.selectedNode}">
<p:ajax event="select" process="#this" update=":form:menus"/>
<p:column headerText="#{msg['name']}">
<h:outputText value="#{document.name}" />
</p:column>
</p:treeTable>
<h:panelGroup id="menus">
<ui:include src="/menu/document_menu.xhtml"/>
</h:panelGroup>
<p:dialog id="document-rename-dialog" widgetVar="documentRenameDialog" header="#{msg.rename}">
<h:panelGrid id="doc-rename" columns="2">
<h:outputLabel for="name" value="#{msg.name}:" />
<h:inputText id="name" value="#{documentsController.name}"/>
</h:panelGrid>
<div class="spacer-10" />
<h:panelGroup layout="block">
<p:commandLink onclick="documentRenameDialog.hide();" value="#{msg.cancel}"/>
<p:commandLink actionListener="#{documentsController.renameDocument(documentsController.selectedNode.data)}"
process="#this :form:document-rename-dialog:doc-rename"
update=":form:docs"
oncomplete="documentRenameDialog.hide();"
value="#{msg.check}">
</h:panelGroup>
</common:dialog>
</h:form>
document_menu page:
<p:contextMenu id="contextMenuDocument" for="docs" nodeType="document">
<p:menuitem value="#{msg.rename}" process="#this docs" update=":form:document-rename-dialog:doc-rename"
actionListener="#{documentsController.setName(documentsController.selectedNode.data.name)}"
rendered="#{documentsController.canWrite}"
icon="ui-icon-pencil" oncomplete="documentRenameDialog.show();"/>
</p:contextMenu>
DocumentsController class:
#ManagedBean
#ViewScoped
public class DocumentsController {
private TreeNode root;
private TreeNode selectedNode;
private String name;
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void renameDocument(ArterDocument selectedDocument) {
if(name != null && !name.equals("")) {
System.out.println("Document renamed in: "+name);
((MyDocument)selectedNode.getData()).setName(name);
}
else
addErrorMessage("Error renaming document.");
}
public static boolean canWrite() {
if(((MyDocument)selectedNode.getData()).isWriteable())
return true;
return false;
}
}
The MyDocument class is a simple class with a String (name) and a boolean (writeable).
Can anyone tell me how I can show filtered contextMenu at first shot?
Thank you!