我需要帮助修复此错误,首先我要获取所有命令然后当我选择一个时我应该获得有关所选命令的更多详细信息。
BaseEntity.java
@MappedSuperclass
public class BaseEntity implements Serializable {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public void setId( Long id ) {
this.id = id;
}
}
Command.java
@Entity
@Table( name = "cmd" )
public class Command extends BaseEntity {
String private name;
//getter&setter
}
CommandDao.java
public Command loadById( Long id ) {
Assert.notNull( id );
Command cmd = null;
Query query = getEntityManger().createQuery( "select u from "
+ getPersistentClass().getSimpleName()
+ " u where u.id= :id" ).setParameter( "id", id );
try {
cmd = (Command) query.getSingleResult();
} catch ( NoResultException e ) {
}
return cmd;
}
@Override
@Transactional( readOnly = true )
public List<Command> listeCmd() {
Query query = getEntityManger().createQuery( "from " + getPersistentClass().getSimpleName() );
List<Command> cmd = (List) query.getResultList();
return cmd;
}
CommandServiceImpl.java
private CommandDao commandDao;
public List<Command> list() {
return commandDao.listeCmd();
}
public Command cmdPick( Long id ) {
List<Command> l = Command Dao.listeCmd();
Command cmd = null;
for ( int i = 0; i < l.size(); i++ ) {
if ( l.get( i ).getId() == id ) {
cmd = commandDao.loadById( id );
}
}
return cmd;
}
的applicationContext.xml
<bean id="commandDao" class="xx.xx.xx.CommandDao" />
<!-- Services Declaration -->
<bean id="commandService" class="xx.xx.xx.CommandServiceImpl">
<property name="commandDao" ref="commandDao" /></property>
</bean>
flow.xml
<var name="command" class="xx.xx.xx.Command" />
<view-state id="shwo" view="show.xhtml" model="command">
<on-render>
<evaluate expression="commandService.liste()" result="viewScope.list"/>
</on-render>
<transition on="pick">
<evaluate expression="commandService.cmdPick(command.getId())"
result="flowScope.list" />
</transition>
</view-state>
Show.xhtml
<h:form>
<p:dataTable var="car" value="#{list}">
<p:column>
<h:outputText value="#{car.name}" />
<h:commandLink action="pick" value="#{car.id}"/>
</p:column>
</p:dataTable>
</h:form>
错误
12:57:22,883 DEBUG ActionExecutor:49 - 执行[EvaluateAction @ 1360f6d expression = commandService.commandService.cmdPick(command.getId()),resultExpression = flowScope.command] 12:57:22,883 DEBUG AnnotatedAction:142 - 放置动作执行属性map [[empty]] 12:57:22,884 DEBUG AnnotatedAction:149 - 清除动作执行属性map [[empty]] 12:57:22,886 DEBUG FlowExecutionImpl:590 - 试图处理[org.springframework.webflow.execution.ActionExecutionException:抛出执行异常[AnnotatedAction @ 127eb1c targetAction = [EvaluateAction @ 1360f6d expression = commandService.commandService.cmdPick(command.getId() ),resultExpression = flowScope.command],attributes = map [[empty]]]处于状态&#39; show&#39; of flow&#39; main&#39; - 动作执行属性是&#39; map [[empty]]&#39;]的根本原因[org.springframework.expression.spel.SpelEvaluationException:EL1004E:(pos 15):方法调用:方法getId()不能可以在java.util.ArrayList上找到] 12:57:22,886 DEBUG FlowExecutionImpl:611 - 重新调整未处理的流程执行异常 12:57:22,887 DEBUG SessionBindingConversationManager:99 - 解锁对话1 mai 31,2014 12:57:22 PM org.apache.catalina.core.StandardWrapperValve invoke GRAVE:servlet [Spring MVC Dispatcher Servlet]的Servlet.service()在路径[/ Colocation]的上下文中引发异常[请求处理失败;嵌套异常是org.springframework.webflow.execution.ActionExecutionException:异常抛出执行[AnnotatedAction @ 127eb1c targetAction = [EvaluateAction @ 1360f6d expression = commandService.commandService.cmdPick(command.getId()),resultExpression = flowScope.command],attributes = map [[empty]]]在州&#39;显示&#39; of flow&#39; main&#39; - 动作执行属性是&#39; map [[empty]]&#39;]的根本原因 org.springframework.expression.spel.SpelEvaluationException:EL1004E:(pos 15):方法调用:在java.util.ArrayList类型上找不到方法getId() 在org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:182) 在org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:106) 在org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57) 在org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:65) 在org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57) 在org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) 在org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:97) 在org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84) 在org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:75) 在org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188) 在org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145) 在org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51) 在org.springframework.webflow.engine.support.ActionTransitionCriteria.test(ActionTransitionCriteria.java:82) 在org.springframework.webflow.engine.support.TransitionCriteriaChain.test(TransitionCriteriaChain.java:71) 在org.springframework.webflow.engine.Transition.canExecute(Transition.java:195) 在org.springframework.webflow.engine.Transition.execute(Transition.java:211) 在org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:393) 在org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214) 在org.springframework.webflow.engine.TransitionableState.handleEvent(TransitionableState.java:119) 在org.springframework.webflow.engine.Flow.handleEvent(Flow.java:555) 在org.springframework.webflow.engine.impl.FlowExecutionImpl.handleEvent(FlowExecutionImpl.java:388) 在org.springframework.webflow.engine.impl.RequestControlContextImpl.handleEvent(RequestControlContextImpl.java:210) 在org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:232) 在org.springframework.webflow.engine.ViewState.resume(ViewState.java:196) 在org.springframework.webflow.engine.Flow.resume(Flow.java:545) 在org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:258) 在org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169) 在org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183) 在org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:48) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:646) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330) 在org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) 在org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) 在org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) 在org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 在org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 在org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:315) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:744)
答案 0 :(得分:0)
您正在为form指定模型,并将viewscope变量指定为渲染上的命令。将此viewscope变量更改为commandList,并在视图中进行相应的更改。然后在commandLink中编写一个JavaScript onclick函数来捕获用户选择的id并在Command中为其分配一个字段。让我们说这个字段在model命令中定义为selectedId。将此值传递给evaluate表达式中的cmdPick方法。