Populate af:table Programmatically from Managead Bean

本文介绍如何使用JavaBean从管理bean填充af:table,展示人员详情数据,包括姓名、电话号码和薪水。通过创建Person类并利用List结构,将数据以表格形式展现于UI界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Instead of populating the data in af:table through model layer (using ViewObject)  using buinding layer, in this article we will introduce how to show the data which is in the managed bean to show on UI in tabular format.

First you should know the number and data type of columns in table, suppose I have to populate a table for person details (name, mobile number and salary). To get and set value of columns I have created a java bean class, it has 3 variable for 3 columns.

Person.java

public class Person{

 

    public Person (String name, String moNo, Integer salary) {

        this.Name = name;

        this.mobNo = moNo;

        this.salary = salary;

    }

    private String Name;

    private String mobNo;

    private Integer salary;

 

    public void setName(String Name) {

        this.Name = Name;

    }

 

    public String getName() {

        return Name;

    }

 

    public void setMobNo(String mobNo) {

        this.mobNo = mobNo;

    }

 

    public String getMobNo() {

        return mobNo;

    }

 

    public void setSalary(Integer salary) {

        this.salary = salary;

    }

 

    public Integer getSalary() {

        return salary;

    }

}

 

Next step, create a managed bean for referencing af:table , this managed bean makes use of person java bean class to add data in same format for all table rows. A List data structure is used to pass all values in af:table.

 

ProgTableBean.java

//ArrayList to poplate data in af:table

    List<Person> personList = new ArrayList();

 

    //To Populate default row in table (Code in Constructor)

 

    public ProgTableBean() {

        personList.add(new Person("Mr.Bean""138xxxxxxx"100));

    }

 

    public void setPersonList(List<Person> personList) {

        this.personList = personList;

    }

 

    public List<Person> getPersonList() {

        return personList;

    }

 

Then, set the value property for the table and columns:

.jsff

<af:table var="row" rowBandingInterval="1" id="t1" value="#{viewScope.ProgTableBean.personList}">

                    <af:column sortable="false" headerText="Name" id="c1" width="150">

                        <af:outputText value="#{row.name}" id="ot1"/>

                    </af:column>

                    <af:column sortable="false" headerText="Mobile Number" id="c2">

                        <af:outputText value="#{row.mobNo}" id="ot2"/>

                    </af:column>

                    <af:column sortable="false" headerText="Salary" id="c3" align="right">

                        <af:outputText value="#{row.salary}" id="ot3"/>

                    </af:column>

                </af:table>

 

Then run the application, we will get a row which contains 3 columns (Name, Mobile Number and Salary).

 

 

REF:

http://www.awasthiashish.com/2014/11/populate-aftable-programmatically-from.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值