Good evening,Im new in jsf,Im tring to put into the datagrid the product that belong to a Marca(Brand) passed by a viewparam this is some jsf code
<f:view>
<f:metadata>
<f:viewParam name="id" value="#{marcaController.id}"/>
</f:metadata>
</f:view>
<ui:composition template="template/template1.xhtml">
<ui:define name="content1">
<div class="product card">
<h:form id="form">
<c:set var="emp" value="#{marcaController.findbyId()}" scope="request" />
<p:dataGrid var="product" value="#{prodottoController.finbyMarca(emp.idmarca)}" multiViewState="true" columns="3" layout="grid"
rows="12" paginator="true" id="cars"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="6,12,16" >
<f:facet name="header">
Products for Sale
</f:facet>
<div class="product-grid-item card" style="margin-bottom: 0">
<div class="product-grid-item-top">
<div>
<i class="pi pi-tag product-category-icon"/>
</div>
</div>
<div class="product-grid-item-content">
<h:graphicImage value="#{product.immagine}" style="width:240px;height:260px" />
<div class="product-name">#{product.nome}</div>
<div class="product-description">#{product.descrizione}</div>
</div>
<div class="product-grid-item-bottom">
<h:outputText value="#{product.prezzo}" styleClass="product-priceline" style="text-decoration:line-through;margin-left:20px;">
<f:convertNumber currencySymbol="€" type="currency"/>
</h:outputText>
<h:outputText value="#{product.prezzoscontato}" styleClass="product-price" style="color:red;font-size:22px;margin-left:20px;">
<f:convertNumber currencySymbol="€" type="currency"/>
</h:outputText>
<br></br>
<div class="brand-name">
</div>
<br></br>
<p:commandButton update=":form:productDetail" oncomplete="PF('productDialog').show()" styleClass="ui-button-warning"
value="Aggiungi Al Carrello"
icon="pi pi-shopping-cart" style="width:inherit;"
>
<f:setPropertyActionListener value="#{product}"
target="#{prodottoController.selected}"/>
</p:commandButton>
</div>
</div>
</p:dataGrid>
In Marca Controller
Marca m=new Marca();
public Integer getId(){
return m.getIdmarca();
}
public void setId(Integer i){
m.setIdmarca(i);
}
public Marca findbyId(){
Integer ident=Integer.valueOf(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"));
m=marcaDao.findById(ident);
return m;
}
it display only the first page of the brands if i change page, server run this exception :
19:59:15,641 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-3) java.lang.NumberFormatException: null
at java.base/java.lang.Integer.parseInt(Integer.java:614)
at java.base/java.lang.Integer.valueOf(Integer.java:983)
at deployment.esem.war//org.negozio.beans.MarcaController.findbyId(MarcaController.java:93)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at [email protected]//javax.el.ELUtil.invokeMethod(ELUtil.java:245)
at [email protected]//javax.el.BeanELResolver.invoke(BeanELResolver.java:338)
at [email protected]//javax.el.CompositeELResolver.invoke(CompositeELResolver.java:198)
at [email protected]//com.sun.el.parser.AstValue.getValue(AstValue.java:110)
at [email protected]//com.sun.el.parser.AstValue.getValue(AstValue.java:177)
at [email protected]//com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
at [email protected]//org.jboss.weld.module.web.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at [email protected]//org.jboss.weld.module.web.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at [email protected]//com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:73)
at [email protected]//com.sun.faces.facelets.tag.jstl.core.SetHandler.apply(SetHandler.java:117)
at [email protected]//javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:55)
at [email protected]//javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at [email protected]//com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:179)
at [email protected]//javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:111)
at [email protected]//javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:55)
at [email protected]//com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:65)
at [email protected]//com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:166)
at [email protected]//com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:372)
at [email protected]//com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:342)
at [email protected]//com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:70)
at [email protected]//javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:55)
at [email protected]//javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at [email protected]//com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:179)
at [email protected]//javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:111)
at [email protected]//javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:55)
at [email protected]//com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:52)
at [email protected]//com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:46)
at [email protected]//com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:271)
at [email protected]//com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:330)
at [email protected]//com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:309)
at [email protected]//com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:162)
at [email protected]//com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:133)
at [email protected]//com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:52)
at [email protected]//com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:46)
at [email protected]//com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:120)
at [email protected]//com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:358)
at [email protected]//com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:266)
at [email protected]//com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:133)
at [email protected]//javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:101)
at [email protected]//javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:101)
at [email protected]//com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:181)
at [email protected]//com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
at [email protected]//com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at [email protected]//com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at [email protected]//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
at [email protected]//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at io.opentracing.contrib.opentracing-jaxrs2//io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at [email protected]//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at [email protected]//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at [email protected]//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at [email protected]//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at [email protected]//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
at [email protected]//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
at [email protected]//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at [email protected]//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at [email protected]//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at [email protected]//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at [email protected]//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at [email protected]//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at [email protected]//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:370)
at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:834)
it dont mantain the state,it change the id on every page changing
why? Thank's Above All!
You get
NumberFormatException
when you callInteger.valueOf(null)
.You should check against
null
infindbyId()
method, depending on your business logic.To understand better
<f:vievParam>
please read this:What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for