It means that data in af:table is not populated through the model layer (Using ViewObject) using the binding layer. let’s say I have some values in our managed bean and have to show records in tabular format on page
So what we have to do –
So what we have to do –
- First, you should know the number and data type of columns in the table, suppose I have to populate a table for person details (name, mobile number and salary). to get and set the value of columns I have created a java bean class, it has 3 variable for 3 columns
// Java Class to set and get value for table column public class PersonBean { public PersonBean(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 is to create a managed bean for referencing af:table , this managed bean makes use of person java bean class to add data in the same format for all table rows. A List data structure is used to pass all values in af:table. See code of managed bean
//ArrayList to poplate data in af:table List<PersonBean> personList = new ArrayList(); //To Populate default row in table (Code in Constructor) public ProgTableBean() { personList.add(new PersonBean("Ashish Awasthi", "xxxxxxxxxx", 50000)); } public void setPersonList(List<PersonBean> personList) { this.personList = personList; } public List<PersonBean> getPersonList() { return personList; }
- Now just drop an af:table on the page and set its properties like value, column header and text values in columns
As I have to show only 3 columns so deleted extra ones
Set properties –
value- from where table collection is populated
columns values- take the var reference of the table and refer variable name in List (here ‘row’ is table var and second is the variable name in person bean class)
value- from where table collection is populated
columns values- take the var reference of the table and refer variable name in List (here ‘row’ is table var and second is the variable name in person bean class)
See the XML source of af:table-
<af:table var="row" rowBandingInterval="1" id="t1" value="#{viewScope.ProgTableBean.personList}" partialTriggers="::b1"> <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>
- Now run this application and see there will be one row in the table as the code is added in the constructor of managed bean to populate one row
- I have added a form and button in the page to add new records in table , see the form source code
<af:panelFormLayout id="pfl1"> <f:facet name="footer"/> <af:inputText label="Name :" id="it1" binding="#{viewScope.ProgTableBean.nameBind}"/> <af:inputText label="Mobile Number :" id="it2" binding="#{viewScope.ProgTableBean.mobNumBind}"/> <af:inputText label="Salary :" id="it3" binding="#{viewScope.ProgTableBean.salaryBind}"> <af:convertNumber/> </af:inputText> <af:button text="Add Record" id="b1" actionListener="#{viewScope.ProgTableBean.addNewRcord}"/> </af:panelFormLayout>
The code in managed bean for button action-
/**Method to add new record in table * @param actionEvent */ public void addNewRcord(ActionEvent actionEvent) { //Get all values using compoenet binding as mobNumBind if (mobNumBind.getValue() != null && nameBind.getValue() != null && salaryBind.getValue() != null) { // Add new Record in List personList.add(new PersonBean(nameBind.getValue().toString(), mobNumBind.getValue().toString(), Integer.parseInt(salaryBind.getValue().toString()))); } }
- Now run and check application-
More posts on POJO Based table –
Get selected row (single/multiple) from POJO based table in ADF
Apply sorting to POJO based af:table programmatically , Using custom sort listener in ADF
Apply sorting to POJO based af:table programmatically , Using custom sort listener in ADF
Thanks, Happy Learning
Download-Sample ADF Application
Download-Sample ADF Application
Excellent article and with lots of information. I really learned a lot here. Do share more like this.
ReplyDeleteUiPath Training in Chennai
Blue Prism Online Training
UiPath Online Training
Great article with lots of information and thanks for sharing!!
ReplyDeleteJava Training in Pune
Java Training in Mumbai
Perfect post with amazing information and thanks for sharing!!
ReplyDeleteSelenium Training in Hyderabad
Selenium Training in Pune