The problem is:
We have a list of objects (we’ll call them Cars) displayed as results from a search in a seam web application. This is displayed as rows, iterating through the results to reference thisCar for the current result in each row. We want to be able to select one of the Cars and open a new window which shows the selected car information, but retains the search results also.

So the current conversation should be brought through to the new window (to keep the current result set), and then the selected Car should be set (starting a new conversation). The s:link tag maintains the conversation, but currently does not work correctly as it is missing a backing datamodel. To add that datamodel would require substantial refactoring, adding a lot of extra seam components just to allow the selection to work.

The broken url is http://localhost:8080/app/page.seam?actionMethod=page.xhtml:selectedCar.setCar(thisCar)&cid=3

Without the backing datamodel, the thisCar variable gets passed into the setCar method as null.

A workaround for this is to use a request parameter in the backing bean and a new method that retrieves the list of results and identifies the correct car to select from that.

In the xhtml page use the s:link tag with a parameter set to the current row id:




In the backing bean that row id is a request parameter:
@RequestParameter
private String rowId;

Use the rowId to determine the correct car:

public void setCar() {
int selected = (Integer.parseInt(rowId));

Iterator it = results.iterator();
while (it.hasNext()) {
Car car= (Car) it.next();
if (car.getId() == selected) {
selectedCar = car;< } }

The url is now: http://localhost:8080/app/page.seam?rowId=3&actionMethod=page.xhtml:selectedCar.setCar(selectedCar)&cid=3