views:

1724

answers:

3

Hi there,

can anyone provide me with an example of how to use th rich:orderingList control? I've gotten to the point where I'm able to display the data as I wanted but now I'd actually like to have the modified order propagated to server. I can't find anything on that subject.

<rich:orderingList value="#{countryHandler.data}" var="country">
    <rich:column>
        <f:facet name="header">
            <h:outputText value="id"/>
        </f:facet>
        <h:outputText value="#{country.id}"/>
    </rich:column>
    <rich:column>
        <f:facet name="header">
            <h:outputText value="code"/>
        </f:facet>
        <h:outputText value="#{country.code}"/>
</rich:column>

and my backing bean has a property data defined that returns just a List<Country>.

So again: how do I populate the changed order of objects back to server?

A: 

Hi,

When you submit the form, Seam will re-order the list (#{countryHandler.data}) for you so you should be able access at this point. I whipped up a quick example to test this. All files are as follows:

CountryHandler.java

@Name("countryHandler")
@Scope(ScopeType.CONVERSATION)
public class CountryHandler {

    @In(create=true)
    private CountryService countryService;

    private List<Country> data;

    public void loadCountries() {
        this.data = this.countryService.getCountryList();
    }

    public List<Country> getData() {
        return data;
    }

    public void setData(List<String> data) {
        this.data = data;
    }

    public void submit() {
        //check the list order here.  You should find it's ordered...
    }
}

Countries.xhtml

...snip...

<rich:orderingList value="#{countryHandler.data}" var="country">
    <rich:column>
        <f:facet name="header">
            <h:outputText value="id"/>
        </f:facet>
        <h:outputText value="#{country.id}"/>
    </rich:column>
    <rich:column>
        <f:facet name="header">
            <h:outputText value="code"/>
        </f:facet>
        <h:outputText value="#{country.code}"/>
</rich:column>
</rich:orderingList>

<h:commandButton action="#{countryHandler.submit()}" value="Submit" />

...snip...

Countries.page.xml

<page>
    ...snip...

    <begin-conversation join="true"/>

    <action execute="#{countryHandler.loadCountries()}"/>

    ...snip...
</page>
Aaron Chambers
+1  A: 

Thanks Aaron for your recepie. I'm not using seam so your solution didn't quite apply in my case. But still - thanks for taking the time!

It's been one of the things that drive me crazy with RichFaces - a complete ignorance when it comes to examples and documentation.

Apparently to be able to use the rich:orderingList element one has to implement a converter. That's kind of obvious if you think about it really hard but it's nowhere to be find in the specs. Once place where I actually found this information is the "Practical RichFaces" book...

Anyways, after implementing the converter and specifying it in the rich:orderingList tag everything works.

Due to the fact that gettings things to work with RF is quite a challenge I've decided to start up an opensource project focusing only on this topic. You can find it at http://richfaces-examples.googlecode.com

For now it's just a set of maven-managed projects with a parent. Description of the problem they are trying to show is actually to be found inside those examples so there's no wiki or anything like that for now (but it's definitelly planned).

Matthias Hryniszak
+1 Because RichFaces drives me crazy for the same reason!
FRotthowe
A: 

Hi there! I need to use ordering list. as u've said I can load the list of elements to ordering list but I can't manage deleting an item from the list. I tried to use activeItem property but it doesn't cooperate with my object in backing bean.

Quite frankly I have not used this component to that extent. I'll try to extend my example to do the deletion but I can't promise anything at this point.
Matthias Hryniszak