11 Replies Latest reply on Sep 23, 2009 11:24 AM by waq

    command link value in datalist

      Hi i am using datalist as

      <rich:dataList value="#{dictionary.dictionayList}" var="dic" type="disc">
       <h:commandLink value="#{dic.guess}" styleClass="link" action="#{dictionary.gessView}"/>
       </rich:dataList>

      Now my requriement is when user clicks the link i need to get the value of the command link clicked in the dictionary.gessView.
      Any help or small example to resolve this issue?

        • 1. Re: command link value in datalist

          Can we bind HtmlDatatable with datalist?

          • 2. Re: command link value in datalist
            nbelaevski

            Hi,

            Use actionListener, because you can get component from the ActionEvent.

            • 3. Re: command link value in datalist

              ok i did as:

              <a4j:outputPanel id="guess_div" layout="none">
               <rich:dataList value="#{dictionary.dictionayList}" var="dic" type="disc">
               <h:commandLink value="#{dic.guess}" styleClass="link" actionListener="#{dictionary.gessView}"/>
               </rich:dataList>
               </a4j:outputPanel>
              

              and
              public void gessView(ActionEvent ae) {
               String wr = ae.getClass().getName();
               System.out.println("Value is ..."+wr);
               }
              

              but its not printing anything

              • 4. Re: command link value in datalist

                it seems that actionlistener is not being called when commandlink is clicked

                • 5. Re: command link value in datalist

                  my issue is still not resolved

                  • 6. Re: command link value in datalist
                    nbelaevski

                    It should be called if action is called for the same component - check server logs, faces messages, etc. for a cause of the problem.

                    • 7. Re: command link value in datalist

                      no its not calling the action method. Nothing is displaying. Let me show you what i m doing:

                      <a4j:outputPanel id="table_div" layout="none">
                      <h:dataTable id="detail_table" value="#{dictionary.dictionayList}" var="dic" border="1" rendered="#{dictionary.visible}" headerClass="datatable_width" style="text-align:left;" binding="#{dictionary.dataTable}">
                       <h:column headerClass="datatable_width">
                       <f:facet name="header">
                       <h:outputText value="" />
                       </f:facet>
                       <h:outputText value="#{dic.word}" styleClass="datatable_text_word"/>
                       </h:column>
                       <h:column headerClass="datatable_width">
                       <f:facet name="header">
                       <h:outputText value="" />
                       </f:facet>
                       <h:outputText value="#{dic.description}" styleClass="datatable_text_desc"/>
                       </h:column>
                       <h:column headerClass="datatable_width">
                       <f:facet name="header">
                       <h:outputText value="" />
                       </f:facet>
                       <h:commandButton value="Details" action="#{dictionary.showDetails}" onclick="showPopup()" />
                       </h:column>
                      </h:dataTable>
                      </a4j:outputPanel>

                      Now this table is updated via an ajax call made by button click:
                      <a4j:commandButton value="Search" action="#{dictionary.searchWord}" reRender="detail_table, table_div"

                      table is populating properly but when i click on command button place inside the datatable, my showDetails is not called. The javascript function showPopup is working properly and it is opening a popup window.
                      Please tell me where i m doing it wrong.

                      • 8. Re: command link value in datalist
                        ilya_shaikovsky

                        First point: #{dictionary} should be session/conversation scoped because rendered attribute value should be kept between requests. And you have it seems in request scope - so it's lost.
                        well explained here http://livedemo.exadel.com/richfaces-demo/richfaces/keepAlive.jsf

                        From the other point - binding should not be pointed to beans which lives more than request. And why you need it at all?

                        • 9. Re: command link value in datalist

                          yes that was the mistake.
                          or alternatively we can also use t:saveState

                          • 10. Re: command link value in datalist

                            ok now i got another issue. The FacesMessage is throwing an exception:

                            SEVERE: java.lang.IllegalStateException
                            javax.faces.el.EvaluationException: java.lang.IllegalStateException
                             at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                             at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                             at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                             at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
                             at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                             at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                             at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                             at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                             at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                             at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                             at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                             at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                             at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                             at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
                             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                             at java.lang.Thread.run(Unknown Source)
                            Caused by: java.lang.IllegalStateException
                             at com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:395)
                             at com.sun.faces.context.FacesContextImpl.addMessage(FacesContextImpl.java:320)
                             at ecs.dictionary.Dictionary.searchWord(Dictionary.java:138)
                             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                             at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                             at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                             at java.lang.reflect.Method.invoke(Unknown Source)
                             at org.apache.el.parser.AstValue.invoke(AstValue.java:152)
                             at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                             at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
                             at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                             ... 29 more
                            

                            Exception is thrown when no data is found and i display the message using rich:message. THe code is as under:
                            FacesMessage message = new FacesMessage("Sorry, No record found.");
                            context.addMessage("search_form", message);
                            

                            <rich:message for="search_form" styleClass="error"/>
                            


                            • 11. Re: command link value in datalist

                              OKay i got the solution. The error was casued because i was storing the context in the instance variable of the bean. We need to call context = FacesContext.getCurrentInstance() everytime the call is made, to avoid java.lang.IllegalStateException.

                              One more issue that really annoying me is that last time i used t:saveState and it worked perfect. But this time when i use t:saveState instead a4j:keepAlive the action is not called for the commandButton.
                              Is saveState can be the replacement of keepAlive?