Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 加载的记录未显示在视图中_Java_Jsf_Primefaces_Jboss7.x_Conversation Scope - Fatal编程技术网

Java 加载的记录未显示在视图中

Java 加载的记录未显示在视图中,java,jsf,primefaces,jboss7.x,conversation-scope,Java,Jsf,Primefaces,Jboss7.x,Conversation Scope,因此,让它相对简单:我有一些Primefaces页面,它应该以表结构表示数据库记录 我将这些记录保存在列表中,该列表位于@ConversationScoped支持bean中。我已经通过调试验证了列表是否正确地填充了数据库中的记录(hibernate db FWIW)。这是在“businessInterface”分发类的帮助下实现的,实际上它只是(数据库)服务类的解耦掩码 如前所述,我已经验证了数据库以及分发服务器是否正确返回了预期值。不幸的是,视图中没有记录,而是显示了空消息 应用程序运行在jB

因此,让它相对简单:我有一些Primefaces页面,它应该以表结构表示数据库记录

我将这些记录保存在
列表中,该列表位于
@ConversationScoped
支持bean中。我已经通过调试验证了列表是否正确地填充了数据库中的记录(hibernate db FWIW)。这是在“businessInterface”分发类的帮助下实现的,实际上它只是(数据库)服务类的解耦掩码

如前所述,我已经验证了数据库以及分发服务器是否正确返回了预期值。不幸的是,视图中没有记录,而是显示了
空消息

应用程序运行在jBoss 7.1.1-Final应用程序服务器上

为了更好的可读性,我在提供的代码周围排除了
h:head
,以及
h:body
ui:composition
ui:define
h:form
,并将列缩短为两种不同的用法(属性显示和动作展示)

视图(缩短和截断):


支持Bean:

@Named
@ConversationScoped
public class CustomerListController implements Serializable {

    private static final long serialVersionUID = -5961625401284927892L;

    private List<Customer> customerList = new ArrayList<Customer>();
    private List<Customer> filteredCustomers = new ArrayList<Customer>();

    @Inject
    CustomerEditController customerEditController;

    @Inject
    CustomerDetailsController customerDetailsController;

    @Inject
    CustomerDistributor businessInterface;

    public String addCustomer() {
        return editCustomer(0l);
    }

    public String editCustomer(long customerId) {
        setFilteredCustomers(null);
        customerEditController.recieveCustomerById(customerId);
        return Pages.CUSTOMER_EDIT;
    }

    public String viewDetails(long customerId) {
        setFilteredCustomers(null);
        customerDetailsController.recieveCustomerById(customerId);
        return Pages.CUSTOMER_DETAILS;
    }

    public String deleteCustomer(long customerIdToDelete) {
        businessInterface.delete(customerIdToDelete);
        setFilteredCustomers(null);
        fillCustomerList();
        return Pages.CUSTOMER_LIST;
    }

    @PostConstruct
    public void fillCustomerList() {
        customerList.clear();
        customerList.addAll(businessInterface.loadAll());

    }

    public List<Customer> getCustomerList() {
        return customerList;
    }

    public List<Customer> getFilteredCustomers() {
        return filteredCustomers;
    }

    public void setFilteredCustomers(List<Customer> filteredCustomers) {
        this.filteredCustomers = filteredCustomers;
    }
}
@Named
@会话范围
公共类CustomerListController实现可序列化{
私有静态最终长serialVersionUID=-5961625401284927892L;
private List customerList=new ArrayList();
private List filteredCustomers=new ArrayList();
@注入
CustomerEdit控制器CustomerEdit控制器;
@注入
CustomerDetailsController CustomerDetailsController;
@注入
客户分销商业务接口;
公共字符串addCustomer(){
返回用户(0l);
}
公共字符串editCustomer(长customerId){
setFilteredCustomers(空);
CustomerEdit控制器。接收CustomerById(customerId);
返回页面。客户_编辑;
}
公共字符串viewDetails(长customerId){
setFilteredCustomers(空);
customerDetailsController.ReceiveCustomerByd(customerId);
返回页面。客户详细信息;
}
公共字符串deleteCustomer(长customerIdToDelete){
businessInterface.delete(customerIdToDelete);
setFilteredCustomers(空);
fillCustomerList();
返回页面。客户列表;
}
@施工后
public void fillerCustomerList(){
customerList.clear();
customerList.addAll(businessInterface.loadAll());
}
公共列表getCustomerList(){
返回客户列表;
}
公共列表getFilteredCustomers(){
退货筛选客户;
}
public void setFilteredCustomers(列出filteredCustomers){
this.filteredCustomers=filteredCustomers;
}
}
当我在
@SessionScoped
中使用支持Bean时,这个过去是有效的,但由于这需要一些黑客的变通方法来产生直观(和预期的)行为,我决定将支持Bean移动到一个较小的范围。因此,我选择了
@ConversationScoped
,因为BackingBean需要比请求生命周期停留更长的时间。。。(同时,为每个请求对数据库运行查询也非常昂贵…)

关于
CustomerEdit控制器
CustomerDetailsController
的简短说明。如果通过单击其中一个按钮请求,他们负责编辑和显示有关单个记录的更多信息

非工作内容是
@PostConstruct public void fillCustomerList()
其他一切都按预期进行


如果您需要任何进一步的信息,请询问,我将根据需要提供上下文;)

我已经找到了一个成功的解决方法,但是它非常粗糙,我真的不喜欢这种方法,因为它在getter中引入了额外的行为。我对backingbean进行了如下修改:

public List<Customer> getCustomerList() {
    if (customerList.size() == 0) {
        fillCustomerList();
    }
    return customerList;
}
@Inject
Conversation conversation;

@PostConstruct
public void init() {
    if(conversation.isTransient()) {
        conversation.end();
    }
    conversation.setTimeout(120000);
    conversation.start();
}
现在,即使没有getter中的hackish行为,它也可以工作(如上所示)

@Inject
Conversation conversation;

@PostConstruct
public void init() {
    if(conversation.isTransient()) {
        conversation.end();
    }
    conversation.setTimeout(120000);
    conversation.start();
}