JSF datatable to Database - jsf

I am doing the following process...in JSF
1)Getting Input from user through the text boxes.
2)when the user clicks the add button I want to display the entered data in datatable so I used Arraylist for displaying in datatable.and also text box should cleared for next entry.
3)User entered another data and click on add button that data also display in grid.
4)when the user check it and click , the data that displaying in datatable with use of arraylist should save on database table.
Note:First three process Done last 4th process is the issue So please help to how to store the data..
Thanks in Advance
My datatable display
<h:column>
<f:facet name="header">Address Id</f:facet>
#{add.address_id}
</h:column>
<h:column>
<f:facet name="header">Customer Id</f:facet>
#{add.customer_id}
</h:column>
<h:column>
<f:facet name="header">Country</f:facet>
#{add.country}
</h:column>
<h:column>
<f:facet name="header">Address1</f:facet>
#{add.address1}
</h:column>
<h:column>
<f:facet name="header">Address2</f:facet>
#{add.address2}
</h:column>
<h:column>
<f:facet name="header">Address3</f:facet>
#{add.address3}
</h:column>
<h:column>
<f:facet name="header">Address4</f:facet>
#{add.address4}
</h:column>
<h:column>
<f:facet name="header">Address2</f:facet>
#{add.address2}
</h:column>
<h:column>
<f:facet name="header">City</f:facet>
#{add.city}
</h:column>
<h:column>
<f:facet name="header">County</f:facet>
#{add.county}
</h:column>
<h:column>
<f:facet name="header">State</f:facet>
#{add.state}
</h:column>
<h:column>
<f:facet name="header">Province</f:facet>
#{add.province}
</h:column>
<h:column>
<f:facet name="header">Postal Code</f:facet>
#{add.postal_code}
</h:column>
<h:column>
<f:facet name="header">Bill To Flag</f:facet>
#{add.bill_to_flag}
</h:column>
<h:column>
<f:facet name="header">Enabled Flag</f:facet>
#{add.enabled_flag}
</h:column>
<h:column>
<f:facet name="header">End Date Active</f:facet>
#{add.end_date_active}
</h:column>
<h:column>
<f:facet name="header">Last Update Date</f:facet>
#{add.last_update_date}
</h:column>
<h:column>
<f:facet name="header">Last Updated By</f:facet>
#{add.last_updated_by}
</h:column>
<h:column>
<f:facet name="header">Province</f:facet>
#{add.province}
</h:column>
<h:column>
<f:facet name="header">Creation Date</f:facet>
#{add.creation_date}
</h:column>
<h:column>
<f:facet name="header">Created By</f:facet>
#{add.created_by}
</h:column>
<h:column>
<f:facet name="header">Last Update Login</f:facet>
#{add.last_update_login}
</h:column>

Typically you need a CRUD page. Checkout the following link
Generate PrimeFaces Pages from Entity Classes in NetBeans
Netbeans prime faces plugin generates CRUD pages from SQL Database using JPA.

To make the things simple, use any of the ORM technologies (Hibernate, JPA, iBatis etc.,), so that each database table record (or row) is identified as an Java object.
Bind the object (technically we call entity) attributes to textboxes
Add the entity to the entity list that renders the datatable
Commit the entity list when user performs aforementioned third action.
Thanks
JK

Related

Using inputRowSelect in a dynamic dataTable

Inside the dataTable dynamically creates a dataTable with the records, how can I get the number of rows for each dataTable that was created?
My Table:
<h:dataTable value="#{bean.tableId}"
var="tableIdInfo" rows="10">
<h:column>
<f:facet name="header">
<h:outputText value="id_date"></h:outputText>
</f:facet>
<h:outputText value="#{tableIdInfo.id_date}"
styleClass="outputText">
<hx:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</h:column>
<h:column>
<h:dataTable value="#{bean.tableList}" var="tInfo">
<h:column>
<f:facet name="header">
</f:facet>
<hx:inputRowSelect value="#{bean.rows}">
</hx:inputRowSelect>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText styleClass="outputText"
value="Date create"></h:outputText>
</f:facet>
<h:outputText value="#{tInfo.cDate}">
<hx:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
I assume tableId is a list of data.
then add a column for getting row numbers.
<h:column>
<!-- display currently selected row number -->
<f:facet name="header">No</f:facet>
#{bean.tableId.rowIndex + 1}
</h:column>

JSF Datatable duplication header

I'm new of JSF, i'm trying to create a datatable but have a problem with this!
This is my code:
JSF file (Datatable):
<h:form>
<h:dataTable value="#{hsinfo.tableContent}" var="o"
styleClass="table"
headerClass="table-header"
rowClasses="table-odd-row,table-even-row">
<h:column>
<f:facet name="header">SBD</f:facet>
<h:outputText value="#{o.sbd}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Họ Tên</f:facet>
<h:outputText value = "#{o.ten}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Ngày Sinh</f:facet>
<h:outputText value = "#{o.ngaysinh}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Giới Tính</f:facet>
<h:outputText value = "#{o.gioitinh}"></h:outputText>
</h:column>
</h:dataTable>
</h:form>
I don't know why if i just use #{o.sbd}, the code have error, but if i use <h:outputText value="#{o.sbd}">, the header row is not appeared and the column name duplicated each row like this :

Unable to send mail from jsf using data table,

public void approveVacation() throws AddressException,MessagingException
String emplname=this.getEmployeeName();
session = FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap();
VacationDTO vacation=new VacationDTO();
vacation.setLeaveId(this.getLeaveId());
vacation.setLeaveDescriptions(this.getLeaveDescriptions());
vacation.setLeaveStartDate(this.getLeaveStartDate());
vacation.setEmployee(getEmployeeService().getUserByEmployeeId(getEmployeeId()));
vacation.setIsApproved((byte)1);
getVacationService().approveVacation(vacation);
String to=vacation.getEmployee().getEmployeeEmailAddress();
String name=vacation.getEmployee().getEmployeeName();
getVacationService().approveVacation(vacation);
Util.sendMail(to, "Hi"+name,
"Your vacation have been approved");
And this is my Xhtml page where I am using List....
<h:form>
<h:dataTable headerClass="header" rowClasses="oddRow,evenRow" value="#{approveVacationBean.vacationList}"
var="list">
<h:column>
<f:facet name="header">Employee Id</f:facet>
#{list.employee.employeeId}
</h:column>
<h:column>
<f:facet name="header">Employee Name</f:facet>
#{list.employee.employeeName}
</h:column>
<h:column>
<f:facet name="header">Leave Applied</f:facet>
#{list.leaveStartDate}
</h:column>
<h:column>
<f:facet name="header">Leave Start Date</f:facet>
#{list.leaveStartDate}
</h:column>
<h:column>
<f:facet name="header">Leave End Date</f:facet>
#{list.leaveEndDate}
</h:column>
<h:column>
<f:facet name="header">No of days</f:facet>
#{list.leaveEndDate}
</h:column>
<h:column>
<f:facet name="header">Paid Leave Balence</f:facet>
#{list.leaveBalance}
</h:column>
<h:column>
<f:facet name="header">Leave Description</f:facet>
#{list.leaveDescriptions}
</h:column>
<h:column>
<f:facet name="header">Comment</f:facet>
<h:inputTextarea ></h:inputTextarea>
</h:column>
<h:column>
<f:facet name="header"></f:facet>
<h:commandButton value="Approve"/>
<h:commandButton value="Reject"/>
</h:column>
</h:dataTable>
I am getting problem in selectiong particular row button.
Many times serive method called...I am using getVacationList() for displaying the list but no mail send to particular employee
First of all, place your approveVacation method in the approveVacationBean.
Then change the method to accept the list as a parameter (I guess it is VacationDTO).
Finally you should link the commandButton with the approveVacation method:
<h:commandButton value="Approve" ajax="false" action="#{approveVacationBean.approveVacation(list)}"/>
Your approveVacation method should look like this:
public void approveVacation(VacationDTO vacation) throws AddressException,MessagingException {
vacation.setIsApproved((byte)1);
getVacationService().approveVacation(vacation);
String to=vacation.getEmployee().getEmployeeEmailAddress();
String name=vacation.getEmployee().getEmployeeName();
getVacationService().approveVacation(vacation);
Util.sendMail(to, "Hi"+name,
"Your vacation have been approved");
}

How can i transfer a column value to my managed bean?

I am using a datatable in JSF:
<h:dataTable var="dataItem" value="#{operationsBean.creneauxMedecin}" border="1">
<f:facet name="header">
<h:outputText value="Rendez-vous de #{operationsBean.medecin.titre} #{operationsBean.medecin.prenom} #{operationsBean.medecin.nom} le #{operationsBean.txtJour}"></h:outputText>
</f:facet>
<h:column>
<f:facet name="header">
<h:outputText value="Créneau horaire"></h:outputText>
</f:facet>
<h:outputText id="id" value="#{dataItem.hdebut}h#{dataItem.mdebut}-#{dataItem.hfin}h#{dataItem.mfin}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Client"/>
</f:facet>
<h:outputText value="#{operationsBean.clt }"/>
</h:column>
</h:dataTable>
Please how can i transfer a column's(((dataItem.id))) value to my managed bean ?
N.B dataItem is a datatable row that contains(id,version,hdebut,mdebut....)
You have to implement an action listener method in your managed bean and call that via a command link and pass a param as part of the tag, if you google you can see many examples.
<h:commandLink value="click me" actionListener="#{managedbean.actionListenerMethod}">
<f:param name="paramInternalId" value="#{dataTableIter.id}" />
</h:commandLink>
http://docs.oracle.com/javaee/5/tutorial/doc/bnaqd.html#bnaqj

How do you get row numbers to show in a <h:dataTable>?

I have the following JSF datatable:
<h:dataTable border="1" var="f2" value="#{someEJB.list}">
<h:column>
<f:facet name="header">No</f:facet>
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>#{f2.name}
</h:column>
</h:dataTable>
How can I show the row numbers?
You can use UIData#getRowIndex() for this.
<h:dataTable binding="#{table}" ...>
<h:column>
#{table.rowIndex + 1}
</h:column>
</h:dataTable>

Resources