tags:

views:

42

answers:

1
public class MyBackingBean{

private List model;

public String search(){
  //change model data
  model = doSearch();
  return "same_view"
}

@PostConstruct
public void init(){
  model = loadDefault()
}

//Other code omitted for clarity
}

And in JSP, for some reasons I use c:foreach to iterate over the model and display the items in a HTML table. The jsp page has got a searh button the action of which is mapped to the #{mybackingbean.search}. So when i click seach, i expect only a subset to be displayed(based on search params) on the same page. The problem i have is that, "When i click on search button,search method is getting invoked and it returns a view name. Since the bean is request scoped, a new instance of the bean is getting created after this and eventually the init method overwrites the results.Meaning, i get the same initial view which displays all the items instead of displaying only the matching items".

What is wrong with this ? And please guide me on the ideal approach to solve this.

+1  A: 
  • don't use redirect, use forward (in your navigation case)
  • if using JSF 2.0, use @ViewScope
  • check MyFaces Orchestra
  • try <a4j:keepAlive> from richfaces
Bozho
How can I modify my navigation case to use forward instead of redirect. Can you give an example?
@user Just an advice - consider using JBoss Seam in combination with JSF and switching the view to facelets instead of JSP. It is a far better combination. You can try it in your future projects.
Petar Minchev
it uses forward by default.
Bozho
@user: If you have `<redirect/>` in navigation case, a redirect will be used. Remove it. A redirect will let the client fire a new GET request which will basically force to create a new bean instance after submit method is been called. A forward won't do that. It will use the same bean in the state as it is after submit method is been called. Your symptoms indicate that you're using a redirect.
BalusC