6 Replies Latest reply on Mar 18, 2009 8:08 PM by Murali Chepuri

    How to call action method and Invoke a Popup when user clicks on s:link

    Murali Chepuri Newbie

      Hi,


      I want to call action method and Invoke a Popup when user clicks on s:link.


      The code may looks like this.



      <a:form>
      <s:link value="Click here for popup1" action="#{bean.showPopup1}"/>
      <rich:modalPanel id="popUp1" rendered="#{bean.displayPopup1}"
      showWhenRendered="true" >
      <!--code for search region -->
      <s:link value="Search" action="#{bean.searchBy}"/>
      <!--Results-->
      <rich:dataTable>
      <rich:columm>
      <!--Click here for popup2-->
      <s:link value="#{row.someValue}" action="#{bean.showPopup2}"/>
      <rich:column>
      </rich:dataTable>
      </rich:modalPanel>
      </a:form>


      Here is what happens


      When user clicks on Click here for popup1, the value of displayPopup1 will be made true in bean.showPopup1


      hence popUp1 will be displayed.


      But when user wants to search for some thing in popUp1 then if he hits on Search(after entering some search fields) popUp is getting collapsed.


      The reason behind it is...displayPopup1 is becoming false.


      So i made it to true again in bean.searchBy.


      But now popup is getting colapsed and re Rendered.Which we dont want when user hits on search.


      Can any body help me... If there is any other way to implement this.


      Thanks
      Murali.



        • 1. Re: How to call action method and Invoke a Popup when user clicks on s:link
          Murali Chepuri Newbie

          Formatted code.



          <a:form> 
             <s:link value="Click here for popup1" action="#{bean.showPopup1}"/> 
             <rich:modalPanel id="popUp1" rendered="#{bean.displayPopup1}" showWhenRendered="true" >
                  
                   <!--code for search region --> 
                   <s:link value="Search" action="#{bean.searchBy}"/>
          
                   <!--Results--> 
                  <rich:dataTable> 
                       <rich:columm> 
                           <!--Click here for popup2--> 
                           <s:link value="#{row.someValue}" action="#{bean.showPopup2}"/> 
                       <rich:column>
                  </rich:dataTable> 
             </rich:modalPanel> 
          </a:form> 


          • 2. Re: How to call action method and Invoke a Popup when user clicks on s:link
            Tim Evers Master

            Please post you SEAM bean code as well. It looks like that would be where the problem could be.

            • 3. Re: How to call action method and Invoke a Popup when user clicks on s:link
              Murali Chepuri Newbie

              Here is SEAM bean code.



              @Name("bean")
              Class Bean{
              public boolean displayPopUp1;
              
              public void showPopup1(){
              this.displayPopUp1=true;
              }
              public void searchBy(){
              
              ....
              some code
              ....
              
              showPopup1();//to show popup again after user hits on search
              
              }
              
              
              
              public void showPopup2(){
              //code to show popup2
              }
              
              
              public boolean isDisplayPopUp1(){
              return displayPopUp1;
              }
              publiv void setDisplayPopUp1(boolean displayPopUp1){
              this.displayPopUp1=displayPopUp1;
              }
              }



              please let me know if this is not sufficient ....


              Thanks
              Murali

              • 4. Re: How to call action method and Invoke a Popup when user clicks on s:link
                Tim Evers Master

                Well, my first assumption is that based on the fact that your SEAM bean has no @Scope annotation then your seam bean will default to EVENT scope.


                This means that your seam bean is getting recreated every event. So all your state is essentially lost on every request.


                Try using @Scope(ScopeType.CONVERSATION) on your bean and see how that goes.


                I would really recommend reading some more SEAM documentation so you understand a bit more about the lifecycle of SEAM components.

                • 5. Re: How to call action method and Invoke a Popup when user clicks on s:link
                  Thai Dang Vu Apprentice

                  I guess your reason to use s:link is that you don't want to submit the form, right? If that's the case then you can refer to my example


                  <a:form>
                      <a:commandLink value="Click here for popup1" action="#{bean.showPopup1}" 
                                     oncomplete="#{rich:component('popUp1')}.show()" ajaxSingle="true"
                                     reRender="popUp1"/>
                      <!-- reason for reRender: most of the time my modal panels are used to display something, when the page is rendered, that "something" is not available yet, when the user clicks on "Click her for popup1", I prepare that "something" in the action method and re-render the modal panel to show that "something"
                           a:commandLink will submit the form, but nothing is updated because of the ajaxSingle = "true" -->
                  </a:form>
                  
                  <rich:modalPanel id="popUp1">
                      <a:form>
                          <a:commandLink value="Show popup2" .../>
                      </a:form>
                  </rich:modalPanel>
                  
                  <rich:modalPanel id="popUp2">...</rich:modalPanel>



                  Hope that helps.

                  • 6. Re: How to call action method and Invoke a Popup when user clicks on s:link
                    Murali Chepuri Newbie
                    Hi,

                    Thanks a lot for your replies.

                    @Thai Dang Vu

                    I would like to request you to notice from code that i have a dataTable with in ModalPanel and with in dataTable i have a commandLink for each row.
                           

                    <!--Results-->
                            <rich:dataTable>
                                 <rich:columm>
                                     <!--Click here for popup2-->
                                     <s:link value="#{row.someValue}" action="#{bean.showPopup2}"/>
                                 <rich:column>
                            </rich:dataTable>


                    So if i use a commandLink in place of s:link and click on someValue in dataTable to show popUp2, the action method(#{bean.showPopup2}) is not getting invoked.This is also one reason which lead me to use s:link.

                    So is there any way to call the action method of a commandLink with in dataTable.