3 Replies Latest reply on Jun 10, 2010 9:38 PM by shanika Dias

    rich:extendedDataTable - How to pop up an alert upon selecting a row

    shanika Dias Newbie

      Hi,

       

      I am having an extendedDataTable. When a user clicks on a row, I want to be able to pop up an alert showing an error message based on a value in that row and unselect it, since it is an invalid selection. 

      - How do I get an alert to popup?

      - Is there any other way to clear the row selection from the gui, instead of having to rerender the entire table upon each row selection to clear the selected row in error? Is it possible   to rerender only the row?

       

      The code

       

       

      here's the code :

       

       


      <a:outputPanel id="toDoListPanel">

                <extendedDataTableid="toDoTable" value="#{itemsToDo}" var="todo" headerClass="thfmt" style="width:100%;"

                  selectionMode="multi" selection="#{ToDo.selection}" rendered="#{itemsToDo.rowCount > 0}">

                ....

                ....

       

               <a:support event="onselectionchange" ignoreDupResponses="true" requestDelay="500" ajaxSingle="true" action="#ToDo.takeSelection}" />

               </rich:extendedDataTable>
      </a:outputPanel>

       

       

       

      in my java code :

       


      private ArrayList<RVersion> selectedItems = new ArrayList<RVersion>();

      private SimpleSelection selection = new SimpleSelection(); 

       

       

       

      public String takeSelection() {      
             selectedItems.clear();
             Iterator<Object> iterator = getSelection().getKeys();
               
             while (iterator.hasNext()) {
                 Object key = iterator.next();

                 RVersion selectedR = todo.get(Integer.parseInt(key.toString()));

              

               if (selectedR.getStatus() != "Pending" || selectedR.getStatus() != "Review"){

                        reportError("Invalid row selected for this operation.");                

       

       

                        selection.removeKey(key);

                        return "";

                }

       

       

                selectedItems.add(todo.get(Integer.parseInt(key.toString())));        
             }     
            
             return null;
          }

       

      Thanks

      -Shanika

        • 1. Re: rich:extendedDataTable - How to pop up an alert upon selecting a row
          Ilya Shaikovsky Master

          as simple solution - you could add your message as FacesMessage to context in your action. Then define modalPanel with rich:messages inside and define oncomplete on button which will execute modal opanel call if facesContext.maximumSeverity returns not null.

          • 2. Re: rich:extendedDataTable - How to pop up an alert upon selecting a row
            Rob Acraman Newbie

            I had just the same problem recently.  If you can add a message property to your bean, and simply generate your final message (including displayed properties) in your method, then you can simply put it in your oncomplete method.

             

            eg:

             

             

            {code}

            private ArrayList<RVersion> selectedItems = new ArrayList<RVersion>();
            private SimpleSelection selection = new SimpleSelection();
            private String message = "";

            public String getMessage() {
                return message;
            }

            public String takeSelection() {     
                   selectedItems.clear();
                   Iterator<Object> iterator = getSelection().getKeys();
                    
                   while (iterator.hasNext()) {
                       Object key = iterator.next();
                       RVersion selectedR = todo.get(Integer.parseInt(key.toString()));

                     if (selectedR.getStatus() != "Pending" || selectedR.getStatus() != "Review"){
                              message = "Invalid row selected for this operation.";               
                              selection.removeKey(key);
                              return "";
                      }

                      selectedItems.add(todo.get(Integer.parseInt(key.toString())));       
                   }    
                 
                   return null;
                }
            {code}

            And in the page:
            {code:xml}
            <a:support event="onselectionchange" action="#ToDo.takeSelection}"
                         oncomplete="if ('#{ToDo.message}' != '') { alert('#{ToDo.message}') };"

            {code}
            • 3. Re: rich:extendedDataTable - How to pop up an alert upon selecting a row
              shanika Dias Newbie

              thanks Rob. This is what I exactly did and it works fine.