-
1. Re: s:link and detecting selected element
cash1981 Jan 25, 2011 10:37 AM (in response to rapuzel125)Many things can happen here.
First, it would be best if you also show the select() method in your bean.
But this should work find when using s:link.
In fact, its the preferred way if you don't need to post anything.So remove the h:form if you are using it and dont need it. Remember that using s:link will not post your form.
Also, please let us know what the nullpointer is saying.
-
2. Re: s:link and detecting selected element
rapuzel125 Jan 25, 2011 4:55 PM (in response to rapuzel125)I'm using seam with EJB and dao pattern i think that can cause problem with conversations maybe, here are my both class
@Stateful @Scope(ScopeType.CONVERSATION) @Name("monitorBean") public class MonitorBean implements MonitorLocal { @In private MonitorDAOLocal monitorDAO; @In private OrganizationcellDAOLocal organizationcellDAO; private List<HardwareMonitor> monitorList; private List<Organizationcell> organizationcellList = new ArrayList<Organizationcell>(); @In(create=true, value="monitor") @Out private HardwareMonitor monitor; @Logger private Log log; @In StatusMessages statusMessages; @Create public void fillMonitors(){ System.out.println("Create MonitorBean"); Organizationcell organizationcell = organizationcellDAO.findOrganizationcell(1); organizationcellList = organizationcellDAO.getUnitStructure(organizationcell); monitorList = monitorDAO.findActiveMonitorsByUnits(organizationcellList); } public List<HardwareMonitor> getMonitors(){ return monitorList; } @Begin(join=true) public void select(HardwareMonitor monitor){ if(monitor != null){ System.out.println("SELECT: " + monitor.getSnumberdu()); this.monitor = monitor; } } @End public String add(){ return PageConstants.SUCCESS; } @End public String edit(){ return PageConstants.SUCCESS; } @End public String delete(){ return PageConstants.SUCCESS; } @End public String cancel(){ return PageConstants.CANCEL; } @Remove @Destroy public void destroy() { System.out.println("Destroy MonitorBean"); } }
@Stateful @Name("monitorDAO") @Scope(ScopeType.CONVERSATION) @AutoCreate public class MonitorDAO implements MonitorDAOLocal { @PersistenceContext(type=PersistenceContextType.EXTENDED) private EntityManager em; private List<HardwareMonitor> monitorList; @Create public void init(){ System.out.println("Create MonitorDAO"); } public List<HardwareMonitor> findActiveMonitorsByUnits(List<Organizationcell> units){ monitorList = em.createQuery("SELECT m FROM monitor m WHERE m.organizationcellByIdcell IN (:organizationcellByIdcell)"). setParameter("organizationcellByIdcell", units).getResultList(); return monitorList; } public List<HardwareMonitor> findMonitorsByUnits(List<Organizationcell> units){ monitorList = em.createQuery("SELECT m FROM monitor m WHERE m.organizationcellByIdcell IN (:organizationcellByIdcell)"). setParameter("organizationcellByIdcell", units).getResultList(); return monitorList; } public void add(HardwareMonitor monitor){ em.persist(monitor); } public void edit(HardwareMonitor monitor){ em.merge(monitor); } public void delete(HardwareMonitor monitor){ em.remove(monitor); } @Remove @Destroy public void destroy() { System.out.println("Destroy MonitorDAO"); } }
and here are my console output
1. When printing dataTable before hiting s:link with select() method
22:48:06,484 INFO [STDOUT] Create MonitorDAO 22:48:06,500 INFO [STDOUT] Create MonitorBean 22:48:09,625 INFO [STDOUT] Destroy MonitorDAO 22:48:09,656 INFO [STDOUT] Create MonitorDAO 22:48:09,656 INFO [STDOUT] Destroy MonitorBean
2. after hiting select()
22:48:25,718 INFO [STDOUT] Create MonitorDAO 22:48:25,718 INFO [STDOUT] Create MonitorBean
-
3. Re: s:link and detecting selected element
cash1981 Jan 26, 2011 5:23 AM (in response to rapuzel125)And the stacktrace please
-
4. Re: s:link and detecting selected element
rapuzel125 Jan 26, 2011 5:55 AM (in response to rapuzel125)Oh, sorry I forgot about stack. If i comment out
if(monitor != null){
then i get:
Exception during request processing: Caused by javax.el.ELException with message: "javax.ejb.EJBTransactionRolledbackException"
and here are part about null pointer stacktrace from seam debug page:
Caused by java.lang.NullPointerException with message: "" mw.wp.keson.action.MonitorBean.select(MonitorBean.java:90) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:592) org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111) org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69) org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:138) org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50) sun.reflect.GeneratedMethodAccessor951.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:592) org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:83) org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:70) org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:59) org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73) org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59) sun.reflect.GeneratedMethodAccessor734.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:592) org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72) org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_21201606.invoke(InvocationContextInterceptor_z_fillMethod_21201606.java) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88) org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_21201606.invoke(InvocationContextInterceptor_z_setup_21201606.java) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:60) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176) org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216) org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207) org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164) $Proxy763.select(Unknown Source) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:592) org.jboss.seam.util.Reflections.invoke(Reflections.java:22) org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43) org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54) org.javassist.tmp.java.lang.Object_$$_javassist_seam_2.select(Object_$$_javassist_seam_2.java) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:592) org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335) org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280) org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59) org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65) org.jboss.el.parser.AstValue.invoke(AstValue.java:96) org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175) org.jboss.seam.navigation.Pages.callAction(Pages.java:692) org.jboss.seam.navigation.Pages.preRender(Pages.java:330) org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:561) org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:472) org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:148) org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:118) com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:214) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:96) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) javax.faces.webapp.FacesServlet.service(FacesServlet.java:266) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178) org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368) org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495) org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53) org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433) org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) java.lang.Thread.run(Thread.java:595)
-
5. Re: s:link and detecting selected element
cash1981 Jan 27, 2011 6:31 AM (in response to rapuzel125)Your code is very confusing.
You are injecting and outjecting monitor, and then you are also setting monitor as parameter in your method. Are you sure this is exactly what you want?
-
6. Re: s:link and detecting selected element
rapuzel125 Jan 27, 2011 4:12 PM (in response to rapuzel125)Indeed that was confusing, but changing that to
@Begin(join=true) public void select(HardwareMonitor monitorSelect){ if(monitorSelect != null){ System.out.println("SELECT: " + monitorSelect.getSnumberdu()); this.monitor = monitorSelect; } }
wasn't help. I also removed DAO but that not helping neither. I attach code for xhtml page
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml"> <ui:define name="body"> <h:form> <rich:panel> <rich:dataTable id="monitorDataTable" onRowMouseOver="this.style.backgroundColor='#e3efff'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" var="r" value="#{monitorBean.monitors}" rendered="#{not empty monitorBean.monitors}" rows="25"> <rich:column sortBy="#{r.sname}" sortOrder="ASCENDING"> <f:facet name="header"> <h:outputText value="#{messages['Monitor.sname']}" /> </f:facet> <h:outputText value="#{r.sname}" /> </rich:column> <rich:column sortBy="#{r.snumberdu}" sortOrder="ASCENDING"> <f:facet name="header"> <h:outputText value="#{messages['Monitor.snumberdu']}" /> </f:facet> <h:outputText value="#{r.snumberdu}" /> </rich:column> <rich:column sortBy="#{r.ndiagonal}" sortOrder="ASCENDING"> <f:facet name="header"> <h:outputText value="#{messages['Monitor.ndiagonal']}" /> </f:facet> <h:outputText value="#{r.ndiagonal}" /> </rich:column> <rich:column sortBy="#{r.reluserhardware.users.slname}" sortOrder="ASCENDING"> <f:facet name="header"> <h:outputText value="#{messages['Monitor.user']}" /> </f:facet> <h:outputText value="#{r.reluserhardware.users.slname} #{r.reluserhardware.users.sfname}" /> </rich:column> <rich:column sortBy="#{r.organizationcellByIdcell}"> <f:facet name="header"> <h:outputText value="#{messages['Monitor.cell']}" /> </f:facet> <h:outputText value="#{r.organizationcellByIdcell}" /> </rich:column> <rich:column> <f:facet name="header"> <h:outputText value="#{messages['Table.Header.Action']}" /> </f:facet> <s:link action="#{monitorBean.select(r)}" value="s link -- " propagation="begin"/> <a:commandLink action="#{monitorBean.select(r)}" value="edit" /> <s:link id="editlink" view="/MonitorEdit.xhtml" action="#{monitorBean.select(r)}" propagation="begin"> <h:graphicImage value="/img/edit.gif" /> </s:link> <s:link id="deletelink" view="/MonitorDelete.xhtml" action="#{monitorBean.select(r)}" propagation="begin"> <h:graphicImage value="/img/delete.gif" /> </s:link> </rich:column> </rich:dataTable> <rich:datascroller renderIfSinglePage="false" id="sc2" for="monitorDataTable" /> </rich:panel> <s:button id="addlink" value="#{messages['Button.create']}" view="/MonitorEdit.xhtml" action="#{monitorBean.select}" propagation="begin" /> </h:form> </ui:define> </ui:composition>
I noticed that when i click on s:link url look like
MonitorList.seam?actionMethod=MonitorList.xhtml%3AmonitorBean.select(r)&conversationPropagation=begin
-
7. Re: s:link and detecting selected element
antibrumm.mfrey0.bluewin.ch Jan 28, 2011 2:40 AM (in response to rapuzel125)Hi
I've never used the s:link together with a view AND action declaration. I think i see one issue here that can cause issues:You call an action with the row entity if i understand your code directly. From what i read in the docs you should not use pass entities directly but just the Ids. Sending entities by reference can cause errors because if you don't use the same conversation the entity can, in the worst case, not exist in the new context or it's detached from the entitymanager etc.
Until now i always used the view declaration together with f:param which contains the id of an entity. And then in the MonitorDelete.page.xml you define this inputparam (or in the bean) and you call an action there.
Hope this can get you somewhere.
Martin
-
8. Re: s:link and detecting selected element
rapuzel125 Jan 28, 2011 3:38 AM (in response to rapuzel125)Thank you for your response.
I also created s:link without view for testing but without luck. Changing select() parameter to id also doesn't help.
Maybe i'll try accomplish that task with @DataModelSelection, but problem with using it was reason for select with parameter method :) -
9. Re: s:link and detecting selected element
cash1981 Jan 28, 2011 7:40 AM (in response to rapuzel125)Correct me if I am wrong, but I can confirm that s:link does not work with parameter like that. You have to use h:commandLink
-
10. Re: s:link and detecting selected element
rapuzel125 Jan 28, 2011 10:12 AM (in response to rapuzel125)OK, im not sure why select() with parameter wasn't working, so I reorganized my code little and now im using @DataModelSelection so it's look like:
@Stateless @Name("monitorDAO") @Scope(ScopeType.EVENT) @AutoCreate public class MonitorDAO implements MonitorDAOLocal { @In(value = "entityManager") private EntityManager em; private List<HardwareMonitor> monitorList; public void init(){ System.out.println("Create MonitorDAO"); } public List<HardwareMonitor> findActiveMonitorsByUnits(List<Organizationcell> units){ monitorList = em.createNamedQuery("HardwareMonitor.findActiveMonitorsByUnits"). setParameter("organizationcellByIdcell", units).getResultList(); return monitorList; } public List<HardwareMonitor> findMonitorsByUnits(List<Organizationcell> units){ monitorList = em.createNamedQuery("HardwareMonitor.findActiveMonitorsByUnits"). setParameter("organizationcellByIdcell", units).getResultList(); return monitorList; } public void add(HardwareMonitor monitor){ em.persist(monitor); } public void edit(HardwareMonitor monitor){ em.merge(monitor); } public void delete(HardwareMonitor monitor){ em.remove(monitor); } }
@Stateful @Scope(ScopeType.CONVERSATION) @Name("monitorBean") public class MonitorBean implements MonitorLocal { @In private MonitorDAOLocal monitorDAO; @In private OrganizationcellDAOLocal organizationcellDAO; @DataModel private List<HardwareMonitor> monitorList; private List<Organizationcell> organizationcellList = new ArrayList<Organizationcell>(); @In(create=true, value="monitor") @Out private HardwareMonitor monitor; @DataModelSelection private HardwareMonitor monitorSelect; @Logger private Log log; @In StatusMessages statusMessages; @Factory("monitorList") public void fillMonitors(){ System.out.println("Create MonitorBean"); Organizationcell organizationcell = organizationcellDAO.findOrganizationcell(1); organizationcellList = organizationcellDAO.getUnitStructure(organizationcell); monitorList = monitorDAO.findActiveMonitorsByUnits(organizationcellList); } @Begin(join=true) public void select(){ if(monitorSelect != null){ System.out.println("SELECT: " + monitorSelect.getSnumberdu()); this.monitor = monitorSelect; } } @End public String add(){ monitorDAO.add(monitor); return PageConstants.SUCCESS; } @End public String edit(){ monitorDAO.edit(monitor); return PageConstants.SUCCESS; } @End public String delete(){ monitorDAO.delete(monitor); return PageConstants.SUCCESS; } @End public String cancel(){ return PageConstants.CANCEL; } @Remove @Destroy public void destroy() { System.out.println("Destroy MonitorBean"); } }