How can it be acheived ?
Is it possible to sort the data by a hidden field (like primary key) before rendering the table ?
Other than that is there any way to a have delete button like edit button when cell editor is used?
Here's my codes
Code: Select all
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>List Users</title>
<link type="text/css" rel="stylesheet" href="resources/themes/cupertino/skin.css" />
</h:head>
<h:body>
<h:form>
<p:panel header="Creat New Record">
<h:panelGrid columns="2">
<h:outputLabel value="Login :" for="txt_login"></h:outputLabel>
<h:inputText id="txt_login" value="#{loginUserManagedBean.loginUser.login}" required="true"/>
<h:outputLabel value="Email :" for="txt_email"></h:outputLabel>
<h:inputText id="txt_email" value="#{loginUserManagedBean.loginUser.email}" required="true"/>
<h:outputLabel value="Password :" for="txt_password"></h:outputLabel>
<h:inputText id="txt_password" value="#{loginUserManagedBean.loginUser.password}" required="true"/>
<h:outputLabel value="Salt :" for="txt_salt"></h:outputLabel>
<h:inputText id="txt_salt" value="#{loginUserManagedBean.loginUser.salt}" required="true"/>
<p:commandButton value="Create" action="#{loginUserManagedBean.createLoginUser}" update="users" />
<p:ajaxStatus style="width:16px;height:16px;">
<f:facet name="start">
<h:graphicImage value="../design/ajaxloading.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
</p:panel>
<p:dataTable id="users" var="user" value="#{loginUserManagedBean.loginUsers}" rowEditListener="#{loginUserManagedBean.updateLoginUser}" widgetVar="loginuser"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" >
<f:facet name="header">
In-Cell Editing Yahoo!!!
</f:facet>
<p:column headerText="Login" style="width:200px">
<h:outputText value="#{user.login}" />
</p:column>
<p:column headerText="Email" style="width:200px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.email}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{user.email}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Password" style="width:200px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.password}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{user.password}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Salt" style="width:12em">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.salt}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{user.salt}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Code: Select all
package managed;
import entity.LoginUser;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import org.primefaces.event.RowEditEvent;
import session.LoginUserFacade;
/**
*
* @author kumarsaurav
*/
@ManagedBean
@SessionScoped
public class LoginUserManagedBean implements Serializable {
@EJB
LoginUserFacade loginUserFacade;
private LoginUser loginUser;
private List<LoginUser> loginUsers;
public LoginUserManagedBean() {
loginUser = new LoginUser();
}
@PostConstruct
private void populateLoginUsers() {
loginUsers = loginUserFacade.findAll();
}
public void createLoginUser() {
loginUserFacade.create(loginUser);
loginUser = new LoginUser();
populateLoginUsers();
}
public void updateLoginUser(RowEditEvent e) {
loginUserFacade.edit((LoginUser)e.getObject());
}
public LoginUser getLoginUser() {
return loginUser;
}
public void setLoginUser(LoginUser loginUser) {
this.loginUser = loginUser;
}
public List<LoginUser> getLoginUsers() {
return loginUsers;
}
public void setLoginUsers(List<LoginUser> loginUsers) {
this.loginUsers = loginUsers;
}
}