estou tentando criar um PostBack no meu projeto, mais sempre que eu submeto o formulário ele traz select que possuo no meu formulário. Ou seja, fica a mesma coisa padrão
public class FacesUtil {
/**
* Método que avalia se é postBack.
* @return
*/
public boolean isPostback(){
return FacesContext.getCurrentInstance().isPostback();
}
/**
* Método que nega o PostBack
* @return
*/
public static boolean isNotPostBack(){
return !isNotPostBack();
}
}
meu Bean
package com.irmaosuspension.controleservico.controller;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.omnifaces.util.Messages;
import com.irmaosuspension.controleservico.enumeration.Categoria;
import com.irmaosuspension.controleservico.jsf.FacesUtil;
import com.irmaosuspension.controleservico.modelo.Fabricante;
import com.irmaosuspension.controleservico.modelo.ModeloCarro;
import com.irmaosuspension.controleservico.service.FabricanteService;
import com.irmaosuspension.controleservico.service.ModeloCarroService;
import com.irmaosuspension.controleservico.util.NegocioException;
import lombok.Getter;
import lombok.Setter;
@Named
@ViewScoped
public class CadastroModeloCarroBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private FabricanteService fabricanteService;
@Inject
private ModeloCarroService modeloCarroService;
@Getter
private List<Fabricante> fabricantes;
@Getter
private List<Categoria> categorias;
@Getter
@Setter
private Fabricante fabricante;
@Getter
@Setter
private ModeloCarro modeloCarro;
public void inicializar() {
System.out.println("Iniciando Modelo Carro");
if(FacesUtil.isNotPostBack()){
fabricantes = fabricanteService.buscarTodos();
categorias = Arrays.asList(Categoria.values());
}
if (this.modeloCarro == null) {
limpar();
}
}
public void salvar() throws NegocioException {
try {
modeloCarroService.salvar(modeloCarro);
Messages.addGlobalInfo("Carro salvo com sucesso!");
limpar();
} catch (NegocioException e) {
Messages.addGlobalError(e.getMessage());
}
}
public void excluir(){
try {
modeloCarroService.excluir(modeloCarro);
Messages.addGlobalInfo("Carro excluído com sucesso!");
} catch (NegocioException e) {
Messages.addGlobalError(e.getMessage());
}
}
public boolean isEditando() {
return this.modeloCarro.getCodigo() != null;
}
private void limpar() {
this.modeloCarro = new ModeloCarro();
}
}
Erro
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/suspension] threw exception [Unresolved compilation problem:
The method isNotPostBack() is undefined for the type FacesUtil
] with root cause
java.lang.Error: Unresolved compilation problem:
The method isNotPostBack() is undefined for the type FacesUtil
at com.irmaosuspension.controleservico.controller.CadastroModeloCarroBean.inicializar(CadastroModeloCarroBean.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2584)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2114)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)