0

Is it possible to call two methods from the Bean to a JSF page within one primefaces component? I have listOfNames() and detailsOfName() methods in the Bean. The two methods return List types.

In a <p:dataGrid>, is it possible to obtain the values from both the methods?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sciFi
  • 161
  • 1
  • 2
  • 9
  • I fail to udnerstand your question. "In a" what? "To a JSF page" - what calls whose methods? – Dariusz Feb 14 '13 at 13:04
  • @Dariusz: Click *edit* to see it. The OP neglected to pay attention and love to formatting rules and question preview. I fixed it. – BalusC Feb 14 '13 at 13:11

2 Answers2

3

You can't invoke multiple properties. Just merge the both lists into one list and return it instead.

E.g.

List<String> listOfEverything = new ArrayList<String>();
listOfEverything.addAll(listOfNames);
listOfEverything.addAll(detailsOfName);

Keep in mind that you should not be doing business job in getter methods. Do the preparing job in bean's (post)constructor or (action)listener method depending on whether you need this on a GET or POST request.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for the answer. (I'll take care to better phrase my question. Thanks once again!) – sciFi Feb 15 '13 at 06:49
1

I would do it the way BalusC proposed, but would also introduce the ability to separate the two lists back, if needed, in your view, or elsewhere, thus returning either List<List<String>>, or Map<String, List<String>>, which is

    List<List<String>> unitedList = new ArrayList<List<String>>();
    unitedList.add(listOfNames);
    unitedList.add(detailsOfName);

or

    Map<String, List<String>> unitedMap = new HashMap<String, List<String>>();
    unitedMap.put("listOfNames", listOfNames);
    unitedList.add("detailsOfName", detailsOfName);
skuntsel
  • 11,624
  • 11
  • 44
  • 67
  • He want to show it in a single ``. Admittedly, there may be more elegant ways, the `DetailsOfName` could perhaps better be a property of `Name`, but ala, the OP asked so and the point is after all that you've to prepare beforehand so that a single result can be returned :) – BalusC Feb 14 '13 at 13:10
  • I think that it is a problem (and an example) of ill design. His bean should contain list of objects with `.name` and `.detail` fields. – skuntsel Feb 14 '13 at 13:18