访问另一个托管Bean中的JSF托管Bean的值 [英] Accessing values of a JSF managed bean in another managed bean
问题描述
我有一个报告生成页面,其中有几个过滤器,例如countryId
,Date
和一些其他参数供用户选择.现在,根据所选的参数,有一个数据库调用,使用这些参数来获取结果列表.
I have a report generation page where I have few filters like countryId
, Date
and few other parameters for the user to select. Now based on the chosen parameters, there is a database call which uses these parameters to fetch a result list .
现在托管的bean包含所有这些搜索参数和结果列表.让我们将此bean命名为Bean1
Now the managed bean contains all these search parameters and the result list .Let us name this bean as Bean1
public class Bean1 implements Constants{
private List<SelectItem> countryList;
private List<String> choosenCountryList;
private List<String> choosenProgramList;
private String invoiceDatePriorTo= CalendarUtilities.getTodaysDate() ;
private List<CustomResults> searchResultList
}
我们还有一个托管bean Bean2
,其中包含Bean1
We have one more managed bean Bean2
which contains a property of Bean1
public class Bean2 implements Constants {
private Bean1 bean1;
public getSearchResults(){
//Code for fetching the search list for bean 1
this.setsearchResultList() //=fetched list from DB;
}
public modifySearchResults(){}
}
现在,当从JSF页面触发操作时,我们调用getSearchResults()
方法,并将searchResultList
设置为在屏幕上显示.这样,我们就可以在屏幕上显示搜索列表
Now when on the trigger of an action from the JSF page we call the getSearchResults()
method and we set the searchResultList
to be displayed in the screen .In this way we are able to display the search list on screen
现在获取的列表将在屏幕上进行用户修改.现在,当我们再次调用ModifySearchResults编辑列表时,由于托管的bean在请求范围内,因此我们无法在bean2中检索列表.
Now the list we get is subjected to user modification on screen .Now when we again call the modifySearchResults to edit the list we are not able to retrieve the list in the bean2 because the managed bean is in request scope .
有人可以告诉我如何继续解决此问题吗?
Can anyone tell me how to go ahead and solve this problem?
推荐答案
只需将您的dataBean声明为ManagedProperty
.
Just declare your dataBean as ManagedProperty
.
从标记中,我认为它与JSF2.0有关.
From the tagging I assume it's about JSF2.0.
您需要在bean2
中将bean1
声明为托管属性.
You need to declare bean1
as managed property in bean2
.
应该看起来像
@ManagedBean
public class Bean1{
}
和
@ManagedBean
public class Bean2{
@ManagedProperty(value="#{bean1}")
Bean1 bean1;
//setter & getter of bean1
}
另请参见
这篇关于访问另一个托管Bean中的JSF托管Bean的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!