I need help fixing this error, in the first place I want to get all commands then when I choose one I should get more detail about command chosen.
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>
Error
12:57:22,883 DEBUG ActionExecutor:49 - Executing [EvaluateAction@1360f6d expression = commandService.commandService.cmdPick(command.getId()), resultExpression = flowScope.command] 12:57:22,883 DEBUG AnnotatedAction:142 - Putting action execution attributes map[[empty]] 12:57:22,884 DEBUG AnnotatedAction:149 - Clearing action execution attributes map[[empty]] 12:57:22,886 DEBUG FlowExecutionImpl:590 - Attempting to handle [org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@127eb1c targetAction = [EvaluateAction@1360f6d expression = commandService.commandService.cmdPick(command.getId()), resultExpression = flowScope.command], attributes = map[[empty]]] in state 'show' of flow 'main' -- action execution attributes were 'map[[empty]]'] with root cause [org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 15): Method call: Method getId() cannot be found on java.util.ArrayList type] 12:57:22,886 DEBUG FlowExecutionImpl:611 - Rethrowing unhandled flow execution exception 12:57:22,887 DEBUG SessionBindingConversationManager:99 - Unlocking conversation 1 mai 31, 2014 12:57:22 PM org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() for servlet [Spring MVC Dispatcher Servlet] in context with path [/Colocation] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@127eb1c targetAction = [EvaluateAction@1360f6d expression = commandService.commandService.cmdPick(command.getId()), resultExpression = flowScope.command], attributes = map[[empty]]] in state 'show' of flow 'main' -- action execution attributes were 'map[[empty]]'] with root cause org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 15): Method call: Method getId() cannot be found on java.util.ArrayList type at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:182) at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:106) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57) at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:65) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57) at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:97) at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84) at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:75) at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188) at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145) at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51) at org.springframework.webflow.engine.support.ActionTransitionCriteria.test(ActionTransitionCriteria.java:82) at org.springframework.webflow.engine.support.TransitionCriteriaChain.test(TransitionCriteriaChain.java:71) at org.springframework.webflow.engine.Transition.canExecute(Transition.java:195) at org.springframework.webflow.engine.Transition.execute(Transition.java:211) at org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:393) at org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214) at org.springframework.webflow.engine.TransitionableState.handleEvent(TransitionableState.java:119) at org.springframework.webflow.engine.Flow.handleEvent(Flow.java:555) at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleEvent(FlowExecutionImpl.java:388) at org.springframework.webflow.engine.impl.RequestControlContextImpl.handleEvent(RequestControlContextImpl.java:210) at org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:232) at org.springframework.webflow.engine.ViewState.resume(ViewState.java:196) at org.springframework.webflow.engine.Flow.resume(Flow.java:545) at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:258) at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169) at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183) at org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:48) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at 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) 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:744)
You are specifying model for form as command and viewscope variable also as command on render. Change this viewscope variable to commandList and make corresponding change in view as well. Then in commandLink write a JavaScript onclick function to capture the id selected by user and assign it a field in Command. Lets say this field defined as selectedId in model command. Pass this value to cmdPick method in evaluate expression.