简体   繁体   English

JSF表单提交问题

[英]Problem with JSF form submit

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. 在JSP中,出于某些原因,我使用c:foreach遍历模型并在HTML表中显示项目。 The jsp page has got a searh button the action of which is mapped to the #{mybackingbean.search} . jsp页面上有一个searh按钮,其动作被映射到#{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". 我遇到的问题是,“当我单击搜索按钮时,搜索方法被调用,并且它返回一个视图名称。由于该bean被请求了作用域,因此在此之后创建了该bean的新实例,并最终创建了init方法。 覆盖结果。意味着,我得到的是相同的初始视图,该视图显示所有项目,而不是仅显示匹配的项目。”

What is wrong with this ? 这有什么问题? And please guide me on the ideal approach to solve this. 并请指导我解决问题的理想方法。

  • don't use redirect, use forward (in your navigation case) 不要使用重定向,请使用转发(在您的导航情况下)
  • if using JSF 2.0, use @ViewScope 如果使用JSF 2.0,请使用@ViewScope
  • check MyFaces Orchestra 查看MyFaces乐团
  • try <a4j:keepAlive> from richfaces 从richfaces尝试<a4j:keepAlive>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM