Sorted sort criterias in Java retrieve

3
Good morning Forum, I need to retrieve data in a java action. This data needs to be sorted. I am using the Core.retrieveXPathQuery method. I can add a sort criteria by passing a map of sort criterias. My problem is, I want the sort criteria List to be sorted but a HashMap is not sorted. Is there any way to achieve this? In a microflow retrieve action, you can sort your sort criteria list. I am pretty sure that it is also possible in a java retrieve. But How? Any ideas?
asked
2 answers
1

You could try a TreeMap with a custom comparator as described in te stackoverflow post below.
This will result in a sorted Map, where you can control the order by writing your own Comparator.


https://stackoverflow.com/questions/12947088/java-treemap-comparator

SortedSet<Map.Entry<String, String>> sortedset = new TreeSet<Map.Entry<String, String>>(
            new Comparator<Map.Entry<String, String>>() {
                @Override
                public int compare(Map.Entry<String, String> e1,
                        Map.Entry<String, String> e2) {
                    return e1.getValue().compareTo(e2.getValue());
                }
            });

To give you an example

    SortedMap<String, String> myMap = new TreeMap<String, String>();
    myMap.put("a", "10.0");
    myMap.put("b", "9.0");
    myMap.put("c", "11.0");
    myMap.put("d", "2.0");
    sortedset.addAll(myMap.entrySet());
    System.out.println(sortedset);

 

answered
-1

In our Java web application, we use Struts2. There is a Member table (column name, phoneno.etc.,) mapped to Address table (columns street, city, zip code, country) using a mapped MemberAddress table (old code, no chance to change the member table to add address columns to it and remove Address table).

When the member profile is edited by a user, he clicks on settings, which directs him to the action class execute) (method. With the logged in member I d, the address object gets something like the code below.

protected String execute() throws Exception {

    Member loginMember = memberDAO.getLoggedInMember();
    memberId = loginMember.getId();
    if (StringUtils.isNotBlank(memberId)) {
        loginMember = memberDAO.getById(memberId);
        Memberaddress memberAddress =   
                      memberAddressDAO.getByMemberId(loginMember.getId());
        Address newAddress = null;
        if (memberAddress != null && memberAddress.getId() != null) {
            newAddress = addressDAO.getById(memberAddress.getId().getAddressid());
        } else {
            newAddress = new Address();
        }
    }
    return SUCCESS;
}

 

if the result is Success, it directs to its results page, memberprofile.jsp, which contains input form fields. Here i want to display the existing profile details, including Address object instance variable i.e, street, city, zipcode. How should i get the Member object & Address object in the jsp page. I am trying

<s:set var="address" value="newaddress"/>

and enter its data in the jsp's input name fields like this.

<input id="addressStreet" type="text"    
 value="<s:property value="#address.addressstreet" escape="false"/>"/>

but I am getting value="" in firebug. I thing am doing something wrong while retrieving the output.

__________________________________

Delete Hacked AOL Account 

answered