命令按钮don';t使用Ajax和Param-JSF2.0
我试图在我的项目中用命令按钮don';t使用Ajax和Param-JSF2.0,ajax,jsf,jsf-2,primefaces,Ajax,Jsf,Jsf 2,Primefaces,我试图在我的项目中用f:ajax和f:param实现一个命令按钮,但没有成功 我有一个名为“纪律Bean”的Bean,它有一个@SessionScoped。在各自的JSF(比如index.xhtml)中,我有一个p:dataTable显示了一些规程(这就是英语中“规程”的意思:p)。当我单击一行时,会打开一个模式,向用户显示“编辑”或“删除”规程的选项。所选对象通过dataTable的selection属性存储在“StructuralElecionada”中自己看: <h:form>
f:ajax
和f:param
实现一个命令按钮,但没有成功
我有一个名为“纪律Bean”的Bean,它有一个@SessionScoped。在各自的JSF(比如index.xhtml)中,我有一个p:dataTable
显示了一些规程(这就是英语中“规程”的意思:p)。当我单击一行时,会打开一个模式,向用户显示“编辑”或“删除”规程的选项。所选对象通过dataTable的selection
属性存储在“StructuralElecionada”中自己看:
<h:form>
<label for="nome">Nome:</label>
<h:inputText styleClass="form-control adicionar" id="nome"
value="#{disciplinaMBean.disciplinaSelecionada.nome}">
</h:inputText>
<h:commandButton id="excluir" styleClass="btn btn-md btn-danger pull-left" value="Excluir" >
<f:param name="idDisciplina" value="#{disciplinaSelecionada.id}" />
<f:ajax event="click" listener="#{disciplinaMBean.deletar}" />
</h:commandButton>
</h:form>
Disciplina deletada:
Nov 01, 2013 10:26:31 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: /edit.xhtml @31,72 listener="#{disciplinaMBean.deletar}": java.lang.NumberFormatException: For input string: ""
javax.el.ELException: /edit.xhtml @31,72 listener="#{disciplinaMBean.deletar}": java.lang.NumberFormatException: For input string: ""
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:447)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at mbeans.DisciplinaMBean.deletar(DisciplinaMBean.java:143)
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:491)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
... 27 more
此模式的代码位于“edit.xhtml”文件中请参阅下面的代码:
<h:form>
<label for="nome">Nome:</label>
<h:inputText styleClass="form-control adicionar" id="nome"
value="#{disciplinaMBean.disciplinaSelecionada.nome}">
</h:inputText>
<h:commandButton id="excluir" styleClass="btn btn-md btn-danger pull-left" value="Excluir" >
<f:param name="idDisciplina" value="#{disciplinaSelecionada.id}" />
<f:ajax event="click" listener="#{disciplinaMBean.deletar}" />
</h:commandButton>
</h:form>
Disciplina deletada:
Nov 01, 2013 10:26:31 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: /edit.xhtml @31,72 listener="#{disciplinaMBean.deletar}": java.lang.NumberFormatException: For input string: ""
javax.el.ELException: /edit.xhtml @31,72 listener="#{disciplinaMBean.deletar}": java.lang.NumberFormatException: For input string: ""
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:447)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at mbeans.DisciplinaMBean.deletar(DisciplinaMBean.java:143)
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:491)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
... 27 more
我知道我调用该方法是因为控制台的日志,但我无法删除该规程,因为我有一个错误(在“idstricta”参数中存储了一个空字符串)
以下是错误:
<h:form>
<label for="nome">Nome:</label>
<h:inputText styleClass="form-control adicionar" id="nome"
value="#{disciplinaMBean.disciplinaSelecionada.nome}">
</h:inputText>
<h:commandButton id="excluir" styleClass="btn btn-md btn-danger pull-left" value="Excluir" >
<f:param name="idDisciplina" value="#{disciplinaSelecionada.id}" />
<f:ajax event="click" listener="#{disciplinaMBean.deletar}" />
</h:commandButton>
</h:form>
Disciplina deletada:
Nov 01, 2013 10:26:31 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: /edit.xhtml @31,72 listener="#{disciplinaMBean.deletar}": java.lang.NumberFormatException: For input string: ""
javax.el.ELException: /edit.xhtml @31,72 listener="#{disciplinaMBean.deletar}": java.lang.NumberFormatException: For input string: ""
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:447)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at mbeans.DisciplinaMBean.deletar(DisciplinaMBean.java:143)
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:491)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
... 27 more
我能做些什么来解决这个问题呢?如果你有EL 2.2,你可以这样做(假设
stricaleselecionada.id
是int
)
谢谢,但是,对不起……什么是EL2.2?我的老师告诉我JSF不能接收参数,必须返回字符串,他不对吗?@FernandoPaladini我能问一下你使用的是哪个操作系统吗?我喜欢that@Fernando:使用EL2.2(表达式语言,这些东西:
{…}
)可以传递参数。是的,如果您想保持当前视图,可以返回void。要执行导航规则,可以返回字符串。您使用的是JSF的哪个版本/实现?如果您使用的是JSF2,那么很可能您使用的是EL2.2。@mohsin:这是Ubuntu。