I am getting an exception trying to poll with PrimeFaces. I'm using solution #1 from Primefaces fileUpload and session timout.
javax.faces.FacesException: class java.lang.Long is not supported as "interval" for p:poll
<p:fileUpload id="fileUploadControl" oncomplete="PF('xmlUploadDialog').hide()"
listener="#{xmlUploadBean.handleFileUpload}" mode="advanced"
allowTypes="/(\.|\/)(xml|zip)$/" update=":mainForm:scriptTableId"
multiple="true" />
<p:poll interval="#{session.maxInactiveInterval - 10}" async="true" />
In PrimeFaces 10, the attribute interval does not take a Long it can take an Integer or Duration.
See the code:
Object interval = poll.getInterval();
int convertedInterval;
if (interval instanceof Integer) {
convertedInterval = (Integer) interval;
}
else if (interval instanceof Duration) {
convertedInterval = (int) ((Duration) interval).getSeconds();
}
else if (interval instanceof String) {
try {
convertedInterval = Integer.parseInt((String) interval);
}
catch (NumberFormatException e) {
throw new FacesException(interval + " is not a valid integer for \"interval\" for p:poll", e);
}
}
else {
throw new FacesException(interval.getClass() + " is not supported as \"interval\" for p:poll");
}
Support for Long was added to PrimeFaces 11.
Related
When trying to edit the cell, method not found exception is thrown. I tried using an ajaxBehaviourEvent, but it is throwing ClassCastException: Sheet can not be cast to Sheet
//view
<p:ajax listener="#{dataListView.cellEditEvent}" process=":form:sheet" update=":form:sheet" >
</p:ajax>
// method
public void cellEditEvent(SheetEvent event) {
org.primefaces.extensions.component.sheet.Sheet sheet = event.getSheet();
List<SheetUpdate> updates = sheet.getUpdates();
HashSet<Sample> processed = new HashSet<Sample>();
int rowUpdates = 0;
for (SheetUpdate update : updates) {
Sample asset = (Sample) update.getRowData();
if (processed.contains(asset))
continue;
entityManager.merge(asset);
System.out.println("Asset " + asset.getEmail() + " updated.");
rowUpdates++;
showSampleData();
}
sheet.commitUpdates();
}
Using PrimeFaces 6.2 and PrimeFacesExtension 6.2.3 and Seam 2.3
I have a search text and I have to search the input text in the same page just like we do search in any web page by ctrl+f it will displays all the occurrences of the input text how to do it in jsf+icefaces. My xhtml is
<h:inputText id="searchTextField" size="12" maxlength="10" value="#{editSplitAsgnsBean.searchTextField}">
</h:inputText>
<ice:commandButton styleClass="buttonPurple" value="#{msgs['EditSplitAsgns.Button.searchButton']}" id="searchButton"
actionListener="#{editSplitAsgnsController.searchButton}">
<ace:ajax execute="#this" render="#sortDataTable" />
</ice:commandButton>
in my controller I am doing this but getting NullPointerException
public void searchButton(ActionEvent e) {
searchTextField = editSplitAsgnsBean.getSearchTextField();
if(isNullOrEmpty(searchTextField)) { return; }
if(!validateInput(searchTextField, true, 10)){
popupHandler.displayMessage(getMessageString(EDIT_SPLIT_ASSIGNMENT_SEARCHSTRING_VALIDATION_MESSAGE));
return;
}
resetSearchData();
findMatchedColumn(SEARCH);
}
public void nextButton(ActionEvent e) {
findMatchedColumn(NEXT);
}
private void findMatchedColumn(String action) {
EditSplitAsgnsData searchRow = null;
String search = editSplitAsgnsBean.getSearchTextField();
if (NEXT.equals(action) && lastFoundIndex != -1) {
index++;
if (matchedColumns.size() > index) {
selectColumn = matchedColumns.get(index);
selectCell(getTable(), lastFoundIndex, selectColumn);
return;
}
}
int newFoundIndex = getTable().findRow(search, selectedColumns, lastFoundIndex + 1, DataTable.SearchType.CONTAINS, true);
matchedColumns.clear();
index = 0;
if (SEARCH.equals(action) && newFoundIndex == -1) {
popupHandler.displayMessage(getMessageString(COMMON_NOSORTSCHEME_DATA_MSG, search));
return;
}
if (NEXT.equals(action) && newFoundIndex == -1) {
popupHandler.displayMessage(getMessageString(EDIT_SPLIT_ASSIGNMENT_SEARCHSTRING_VALIDATION_MESSAGE, search));
searchFlag = false;
selectCell(getTable(), lastFoundIndex, selectColumn);
return;
}
searchFlag = true;
getTable().navigateToRow(newFoundIndex);
getTable().setRowIndex(newFoundIndex);
searchRow = (EditSplitAsgnsData) getTable().getRowData();
searchMatches(searchRow, search);
if (!CollectionsUtil.isNullOrEmpty(matchedColumns)) {
selectColumn = matchedColumns.get(index);
}
lastFoundIndex = newFoundIndex;
selectCell(getTable(), lastFoundIndex, selectColumn);
}
private void resetSearchData() {
lastFoundIndex = -1;
selectColumn = -1;
searchFlag = false;
}
Stack Trace
java.lang.NullPointerException
at com.fedex.emea.gss.controller.EditSplitAsgnsController.findMatchedColumn(EditSplitAsgnsController.java:483)
at com.fedex.emea.gss.controller.EditSplitAsgnsController.searchButton(EditSplitAsgnsController.java:464)
at com.fedex.emea.gss.controller.EditSplitAsgnsController$$FastClassByCGLIB$$6f1285ca.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.fedex.emea.gss.controller.EditSplitAsgnsController$$EnhancerByCGLIB$$6e6697f4.searchButton(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:775)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
I am new to jsf so dont know how to fix the issue
Your problem is in the execute="#this", this means you are only sending the command button in your request but not your Textfield.
In order to fix this, here are possible solutions
execute="#form" will send all the form attributes in the request
execute="searchTextField" will send the searchTextFieldId in the request. This is the best solution. Take care of the path of the "searchFieldId". You need to use the full path
As another advice, I usually use the "listener" attribute of the "ajax" and avoid "actionListener". Theoritically you dont need ajax with commandbutton. commandButton uses already ajax. Hope this helps
I have a method that calculates a charge but you need to click the button twice for it to calculate
This is the method that fetches the data in the database and calculates
public Float findTarifaBandeira1() {
try {
//SQL
} catch (NoResultException ne) {
System.out.print("Tarifa não encontrada"); // Colocar messagesfaces
}
tarifaBand1 = (bandeira.getValorInicial() + ( bandeira.getTarifaCorrida().getValorKm() * km));
BigDecimal vt = new BigDecimal(tarifaBand1).setScale(2, RoundingMode.HALF_EVEN);
tarifaBand1 = vt.floatValue();
return tarifaBand1;
}
This method fires the click of the button calls other methods and the method above
I have a method that calculates a charge but you need to click the button twice for it to calculate
public void consultarBandeira() throws ParseException {
getData();
getHora();
convertDistance();
findTarifaBandeira1();
findTarifaBandeira2();
findTarifaVolumesDeMao ();
findTarifaVolumesNormais ();
findTarifaVolumesGrandes();
}
In my JSF page I use a remote command to call the above method
<p:commandButton value="#{msg['btn-search']}"
styleClass="btn btn-primary" onclick="findRoute()"/>
<p:remoteCommand actionListener="#{searchBean.consultarBandeira()}"
id="consultaValor" name="consultaValor"
update="bandeira1, bandeira2, nomeVPequenos,
descricaoVPequenos, valorVpequenos, nomeVNormais,
descricaoVNormais, valorVNormais, nomeVGrandes,
descricaoVGrandes, valorVGrandes"/>
findRoute() is a function that calls the JavaScript consultaValor component that triggers the method in my searchBean.
function findRoute(){
event.preventDefault();
var addressOrigin = origin;
var addressDestination = document.getElementById("addr").value +
document.getElementById("city").value;
var request = {
origin: addressOrigin,
destination: addressDestination,
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.metric
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
directionsDisplay.setPanel(document.getElementById("route"));
var route = response.routes[0];
for (var i = 0; i < route.legs.length; i++){
routeSegment = i + 1;
distance = route.legs[i].distance.value;
}
document.getElementById("distance").value = distance;
}
});
consultaValor();
}
When you click the commandButton, it does a postback to the server twice: once for the remoteCommand and once for the button itself. This is most likely the cause of your problem.
Since you're essentially using the button for client-side action only, instruct your commandButton to not postback via onclick.
Also, since you're setting form data in the findRoute() javascript method, you'll need to make sure it is processed on the backend. The default value of process for remoteCommand is #this.
<p:commandButton value="#{msg['btn-search']}"
styleClass="btn btn-primary" onclick="findRoute(); return false"/>
<p:remoteCommand actionListener="#{searchBean.consultarBandeira()}"
id="consultaValor" name="consultaValor"
process="#form"
update="bandeira1, bandeira2, nomeVPequenos,
descricaoVPequenos, valorVpequenos, nomeVNormais,
descricaoVNormais, valorVNormais, nomeVGrandes,
descricaoVGrandes, valorVGrandes"/>
But if it were me, I'd simplify this by combining the logic into the commandbutton itself:
<p:commandButton value="#{msg['btn-search']}"
styleClass="btn btn-primary" onstart="findRoute()"
action="#{searchBean.consultarBandeira()}"
process="#form"
update="bandeira1, bandeira2, nomeVPequenos,
descricaoVPequenos, valorVpequenos, nomeVNormais,
descricaoVNormais, valorVNormais, nomeVGrandes,
descricaoVGrandes, valorVGrandes" />
I have the following code:
<p:remoteCommand name="navigateTo" actionListener="#{searchControllerHelper.dummyActionListener}"
action="#{searchControllerHelper.navigateTo}" update="searchPanelForm"
onstart="plsWaitDlg.show()" onsuccess="plsWaitDlg.hide()"/>
Controller Code as under:
Thank you Lars. Code of the bean as under:
public String navigateTo() throws FetchException {
if (null == this.getSelectedMenuLink()) {
return null;
}
if (this.getSelectedMenuLink().longValue() == 1L) {
this.prevSelectedMenuLink = this.selectedMenuLink;
this.location = null;
return searchCRE();
}
else if (this.getSelectedMenuLink().longValue() == 2L) {
this.prevSelectedMenuLink = this.selectedMenuLink;
this.selectedLoanType=null;
return searchLoans();
}
else if (this.getSelectedMenuLink().longValue() == 3L) {
this.prevSelectedMenuLink = this.selectedMenuLink;
this.selectedLoanType=null;
return searchLoans();
}
else if (this.getSelectedMenuLink().longValue() == 4L) {
this.prevSelectedMenuLink = this.selectedMenuLink;
return otherOpportunities();
}
else if (this.getSelectedMenuLink().longValue() == 5L) {
//The link needs to be 'activated' once a service provider is selected.
this.prevSelectedMenuLink= this.selectedMenuLink;
return this.navigateToHome();
}
return null;
}
I added the actionlistener to check if the controller was getting fired or not, and it is.
What is happening is the following: The page loads, and before it is completely done loading if the user clicks the button that calls this remoteCommand then strangely the actionListener gets called, but the action method does not.
Any ideas what I could do to alleviate this issue?
Thank you
Karthik
when I an offer create an oferta object (offer) it saves all of the items in the select many check box (this are location as per company selected(empresa)), not only the checked ones:
Thank you very much for any help you can provide.
<h:outputLabel value="#{bundle.CreateOfertaLabel_empresaidEmpresa}" for="empresaidEmpresa" />
<h:selectOneMenu id="empresaidEmpresa"
value="#{ofertaController.selected.empresaidEmpresa}"
title="#{bundle.CreateOfertaTitle_empresaidEmpresa}"
required="true"
requiredMessage="#{bundle.CreateOfertaRequiredMessage_empresaidEmpresa}">
<f:ajax event="valueChange" execute="empresaidEmpresa" render="ubicacionCollection" />
<f:selectItems value="#{empresaController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="#{bundle.CreateOfertaLabel_ubicacionCollection}" for="ubicacionCollection" />
<h:selectManyCheckbox id="ubicacionCollection"
value="#{ubicacionXEmpresa}"
title="#{bundle.CreateOfertaTitle_ubicacionCollection}" >
<f:converter id="ubicacionConverter" converterId="ubicacionConverter"/>
<f:selectItems id="ubicacionCollectionItems"
value="#{ofertaController.selected.empresaidEmpresa.ubicacionCollection}"
var="ubicacionXEmpresa"
itemLabel="#{ubicacionXEmpresa.barrio}"
itemValue="#{ubicacionXEmpresa}"/>
</h:selectManyCheckbox>
Your correct the lines should be:
<h:outputLabel value="#{bundle.CreateOfertaLabel_ubicacionCollection}" for="ubicacionCollection" />
<h:selectManyCheckbox id="ubicacionCollection"
value="#{ofertaController.selected.ubicacionCollection}"
title="#{bundle.CreateOfertaTitle_ubicacionCollection}" >
<f:converter id="ubicacionConverter" converterId="ubicacionConverter"/>
<f:selectItems id="ubicacionCollectionItems"
value="#{ofertaController.selected.empresaidEmpresa.ubicacionCollection}"
var="ubicacionXEmpresa"
itemLabel="#{ubicacionXEmpresa.barrio}"
itemValue="#{ubicacionXEmpresa}"/>
</h:selectManyCheckbox>
But know faces show me this on creation of an offer
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '32-1' for key 'PRIMARY' Error Code: 1062 Call: INSERT INTO oferta_has_ubicacion (ubicacion_idUbicacion, oferta_idOferta) VALUES (?, ?) bind => [2 parameters bound] Query: DataModifyQuery(name="ubicacionCollection" sql="INSERT INTO oferta_has_ubicacion (ubicacion_idUbicacion, oferta_idOferta) VALUES (?, ?)")
Here is my create method:
public void create(Oferta oferta) {
if (oferta.getUbicacionCollection() == null) {
oferta.setUbicacionCollection(new ArrayList<Ubicacion>());
}
if (oferta.getEmpresaCollection() == null) {
oferta.setEmpresaCollection(new ArrayList<Empresa>());
}
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Empresa empresaidEmpresa = oferta.getEmpresaidEmpresa();
if (empresaidEmpresa != null) {
empresaidEmpresa = em.getReference(empresaidEmpresa.getClass(), empresaidEmpresa.getIdEmpresa());
oferta.setEmpresaidEmpresa(empresaidEmpresa);
}
Collection<Ubicacion> attachedUbicacionCollection = new ArrayList<Ubicacion>();
for (Ubicacion ubicacionCollectionUbicacionToAttach : oferta.getUbicacionCollection()) {
ubicacionCollectionUbicacionToAttach = em.getReference(ubicacionCollectionUbicacionToAttach.getClass(), ubicacionCollectionUbicacionToAttach.getIdUbicacion());
attachedUbicacionCollection.add(ubicacionCollectionUbicacionToAttach);
}
oferta.setUbicacionCollection(attachedUbicacionCollection);
Collection<Empresa> attachedEmpresaCollection = new ArrayList<Empresa>();
for (Empresa empresaCollectionEmpresaToAttach : oferta.getEmpresaCollection()) {
empresaCollectionEmpresaToAttach = em.getReference(empresaCollectionEmpresaToAttach.getClass(), empresaCollectionEmpresaToAttach.getIdEmpresa());
attachedEmpresaCollection.add(empresaCollectionEmpresaToAttach);
}
oferta.setEmpresaCollection(attachedEmpresaCollection);
em.persist(oferta);
if (empresaidEmpresa != null) {
empresaidEmpresa.getOfertaCollection().add(oferta);
empresaidEmpresa = em.merge(empresaidEmpresa);
}
for (Ubicacion ubicacionCollectionUbicacion : oferta.getUbicacionCollection()) {
ubicacionCollectionUbicacion.getOfertaCollection().add(oferta);
ubicacionCollectionUbicacion = em.merge(ubicacionCollectionUbicacion);
}
for (Empresa empresaCollectionEmpresa : oferta.getEmpresaCollection()) {
empresaCollectionEmpresa.getOfertaCollection().add(oferta);
empresaCollectionEmpresa = em.merge(empresaCollectionEmpresa);
}
em.getTransaction().commit();
} finally {
if (em != null) {
em.close();
}
}
}
value="#{ofertaController.selected.ubicacionCollection}"
The other was a many to many relationship problem jpa issue