1 2 Previous Next 25 Replies Latest reply on May 27, 2009 6:19 PM by Scott Farley

    Ordering bean values using rich:orderingList

    Ruben Jorge Newbie

      Hello everyone,

      I'm trying to use an ordering list to sort items and I would like to apply those changes to the values in my backing bean.

      I can display the items perfectly and order them in the client side, however, I don't know how to apply the changes to the actual data.

      I believe this has to be done using a listener, however the one I defined is never called. Here is the related JSF code:

      <h:form>
       <h:panelGrid columns="2" columnClasses="top 70per, top 30per" width="100%">
       <rich:orderingList id="list" value="#{MatrixBean.elements}" var="lib" listHeight="300" listWidth="350" valueChangeListener="#{MatrixBean.orderListener}">
       <rich:column width="180">
       <f:facet name="header">
       <h:outputText value="Name" />
       </f:facet>
       <h:outputText value="#{lib.name}"></h:outputText>
       </rich:column>
       </rich:orderingList>
       </h:panelGrid>
       </h:form>
       </rich:modalPanel>
       </h:form>
      


      Any ideas please?

      Thanks in advance,
      ~Ruben

        • 1. Re: Ordering bean values using rich:orderingList
          Ruben Jorge Newbie

          Nevermind the last two lines in the code, they are the ending tags of something else. I also removed the nested forms but it still doesn't work.

          • 3. Re: Ordering bean values using rich:orderingList
            Ilya Shaikovsky Master

            do not forget about converter for objects and hashCode, equals methods overriding.

            • 4. Re: Ordering bean values using rich:orderingList
              Nick Belaevski Master

              Hi Ruben,

              RF-6620 couldn't be reproduced, rich:OL works fine on livedemo and nanother examples. For your case - there should be some component submitting data to server, so you have to add one, e.g. a4j:commandButton.

              Also there's one more error in your code - nested forms. JSF strictly forbids that.

              • 5. Re: Ordering bean values using rich:orderingList
                Ruben Jorge Newbie

                Thank you for your replies.

                My code is now as follows:

                <h:form id="formOrder">
                 <rich:modalPanel id="order" width="500" height="400">
                
                 <f:facet name="header">
                 <h:panelGroup>
                 <h:outputText value="Order attributes"></h:outputText>
                 </h:panelGroup>
                 </f:facet>
                 <f:facet name="controls">
                 <h:panelGroup>
                 <h:commandLink id="closeLink2" value="Close"/>
                 <rich:componentControl for="panel" attachTo="closeLink2" operation="hide" event="onclick"/>
                 </h:panelGroup>
                 </f:facet>
                
                 <!-- list -->
                 <h:panelGrid columns="2" columnClasses="top 70per, top 30per" width="100%">
                 <rich:orderingList id="list" value="#{MatrixBean.attributes}" var="lib" listHeight="300" listWidth="350" valueChangeListener="#{MatrixBean.orderListener}">
                 <rich:column width="180">
                 <f:facet name="header">
                 <h:outputText value="Name" />
                 </f:facet>
                 <h:outputText value="#{lib.name}"></h:outputText>
                 </rich:column>
                 </rich:orderingList>
                
                 <a4j:commandButton value="Submit" action="#"/>
                 </h:panelGrid>
                
                 </rich:modalPanel>
                 </h:form>
                


                nbelaevski, I now have a button I want to use to submit data to the server, but I don't know what kind of backing bean method to associate with it. Do you know where I can find an example of orderingList with backing bean code?

                Also, does this mean I don't need an event listener to update data in the bean?

                ilya_shaikovsky, each of my elements is constituted by a String and a few int. I can display their properties fine in the list, I just can't update the order on the data structure. Do I need to use a converter for that class anyway? If so, can you direct me to an example please?

                Thank you again.

                • 6. Re: Ordering bean values using rich:orderingList
                  Ilya Shaikovsky Master

                  in our modal panel usage section in dev guide we have the forms limitation. You should not forget about it.

                  form should be inside the modal. (but nested forms not allowed, so the panel should not be inside another form).. Also read about domElementAttachment attribute which could be used to drop this limitation.

                  • 7. Re: Ordering bean values using rich:orderingList
                    Ruben Jorge Newbie

                    ilya_shaikovsky, I've read about the usage of forms in the modal panel it and I changed my code. I now have the form inside the modal panel, however the content of both my "facet" inside the modal panel are not rendered now.

                    My modal panel is not inside any form tag now, just has one inside it:

                    <rich:modalPanel id="order" width="500" height="400">
                     <h:form id="formOrder">
                     ...............
                     </h:form>
                    </rich:modalPanel>
                    
                    
                    I still don't know how to submit and update the data on the server. I have a button I want to use to submit data to the server, but I don't know what kind of backing bean method to associate with it.
                    


                    • 8. Re: Ordering bean values using rich:orderingList
                      Ruben Jorge Newbie

                      I still don't know how to submit and update the data on the server. I have a button I want to use to submit data to the server, but I don't know what kind of backing bean method to associate with it.

                      • 9. Re: Ordering bean values using rich:orderingList
                        Ilya Shaikovsky Master

                        should be

                        <modal>
                        <facet>
                        </facet>
                        <form >
                        ...
                        .....Closing tags


                        • 10. Re: Ordering bean values using rich:orderingList
                          Ruben Jorge Newbie

                          Got it, thank you again.

                          I'm looking for examples on how to update data on the server, if you know where I can see a few examples it would be appreciated.

                          Thanks in advance.

                          • 11. Re: Ordering bean values using rich:orderingList
                            Ilya Shaikovsky Master

                            how about livedemo sample? Please visit the link in my signature to check the demo sources and other usefull resources.

                            • 12. Re: Ordering bean values using rich:orderingList
                              Ruben Jorge Newbie

                              ilya_shaikovsky, on live demo there is only the code for the JSF, not the backing bean.

                              I found an example somwhere else and I created a converter for my class, however it still doesn't update the list in the bean.

                              I have a panel with an orderingList and a a simple dataOrderedList, both connected to the same data. I re-order the items, click submit but the items in the second list are always in the original order.

                              My page:

                              <rich:panel>
                               <f:facet name="header">
                               Using rich:orderingList
                               </f:facet>
                               <h:panelGrid columns="2">
                               <h:panelGroup>
                               <h:form>
                               <rich:orderingList id="list" value="#{MatrixBean.attributes}" var="lib" listWidth="350" converter="attributeConverter">
                               <h:column>
                               <f:facet name="header">Name</f:facet>
                               <h:outputText value="#{lib.name}"></h:outputText>
                               </h:column>
                               <h:column>
                               <f:facet name="header">ID</f:facet>
                               <h:outputText value="#{lib.id}"></h:outputText>
                               </h:column>
                               </rich:orderingList>
                               <a4j:commandButton value="Submit" reRender="hardList" />
                               </h:form>
                               </h:panelGroup>
                               <h:panelGroup>
                               <rich:dataOrderedList value="#{MatrixBean.attributes}" var="at" id="hardList">
                               <h:outputText value="#{at.name}"/>
                               </rich:dataOrderedList>
                               </h:panelGroup>
                               </h:panelGrid>
                               </rich:panel>
                              



                              Backing bean:

                              public class MatrixBean {
                              private Vector<SOLAPAttribute> attributes;
                              
                               public Vector<SOLAPAttribute> getAttributes() {
                               return attributes;
                               }
                               public void setAttributes(Vector<SOLAPAttribute> attributes) {
                               this.attributes = attributes;
                               }
                              
                              }
                              



                              Element class:

                              public class SOLAPAttribute {
                               private String dimensionId;
                               private String levelId;
                               private String id;
                               private String name;
                              
                               public SOLAPAttribute() {
                               }
                              
                               public SOLAPAttribute(String id, String name, String dimensionId, String levelId) {
                               this.id = id;
                               this.name = name;
                               this.dimensionId = dimensionId;
                               this.levelId = levelId;
                               }
                              
                               public SOLAPAttribute(SOLAPAttribute clone) {
                               this.id = clone.getId();
                               this.name = clone.getName();
                               this.dimensionId = clone.getDimensionId();
                               this.levelId = clone.getLevelId();
                               }
                              
                               //****** required for converter ******
                               public String toString() {
                               return id+":"+name+":"+dimensionId+":"+levelId;
                               }
                               @Override
                               public int hashCode() {
                               final int prime = 31;
                               int result = 1;
                               result = prime * result + ((id == null) ? 0 : id.hashCode());
                               result = prime * result + ((name == null) ? 0 : name.hashCode());
                               result = prime * result + ((dimensionId == null) ? 0 : dimensionId.hashCode());
                               result = prime * result + ((levelId == null) ? 0 : levelId.hashCode());
                              
                               return result;
                               }
                               @Override
                               public boolean equals(Object obj) {
                               if (this == obj)
                               return true;
                               if (obj == null)
                               return false;
                               if (getClass() != obj.getClass())
                               return false;
                               final SOLAPAttribute other = (SOLAPAttribute)obj;
                              
                              
                               if (id == null) {
                               if (other.id != null)
                               return false;
                               } else if (!id.equals(other.id))
                               return false;
                              
                               return true;
                               }
                               //************************************
                              
                               //accessors ...
                              }
                              



                              Converter:

                              public class AttributeConverter implements Converter{
                              
                               public Object getAsObject(FacesContext context,
                               UIComponent component, String value) {
                              
                               String[] words = value.split(":");
                               String id = words[0];
                               String name = words[1];
                               String dimensionId = words[2];
                               String levelId = words[3];
                              
                               SOLAPAttribute attribute = new SOLAPAttribute(id, name, dimensionId, levelId);
                              
                               return attribute;
                               }
                              
                               public String getAsString(FacesContext facesContext,
                               UIComponent uiComponent, Object value) {
                              
                               return value.toString();
                               }
                              }
                              



                              Added the following to faces-config:

                              <converter>
                               <converter-id>attributeConverter</converter-id>
                               <converter-class>solap.utils.AttributeConverter</converter-class>
                               </converter>
                              


                              I don't know what's wrong. Everything is working fine except that the list is not updated on the main bean.

                              Any ideas please?

                              • 13. Re: Ordering bean values using rich:orderingList
                                Nick Belaevski Master

                                Have you tried this with 3.3.1.GA?
                                Do you use any custom filters? Please post web.xml

                                • 14. Re: Ordering bean values using rich:orderingList
                                  Ilya Shaikovsky Master

                                  visit the link in our signatures and get links to full code sources

                                  1 2 Previous Next