Perfect table
xhtml
<!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:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<h:body>
<h:form id="form">
<p:messages id="msgs" autoUpdate="true" />
<p:panel header="Data Items" style="margin-buttom:10px">
<h:panelGrid id="grid" columns="3" cellpadding="5">
<h:outputLabel value="Id :" for="Id" />
<p:inputText id="Id" value="#{beanPerfectTable.var.id}" required="true" >
<f:validateLength minimum="5" maximum="5"/>
</p:inputText>
<p:message for="Id" display="icon"/>
<h:outputLabel value="Item :" for="Item" />
<p:inputText id="Item" value="#{beanPerfectTable.var.item}" required="true" placeholder="Rp.000.0"/>
<p:message for="Item" display="icon"/>
<h:outputLabel value="Price :" for="Price" />
<p:inputText id="Price" value="#{beanPerfectTable.var.price}">
<f:convertNumber type="currency" currencySymbol="Rp."/>
</p:inputText>
<p:message for="Price" display="icon"/>
<h:outputLabel value="Unit :" for="Unit" />
<p:selectOneMenu id="Unit" value="#{beanPerfectTable.var.unit}">
<f:selectItem itemLabel="Select One Menu" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{beanPerfectTable.units}"/>
</p:selectOneMenu>
<p:message for="Unit" display="icon"/>
<h:outputLabel value="Qty :" for="Qty" />
<p:inputText id="Qty" value="#{beanPerfectTable.var.qty}" >
<f:validateDoubleRange minimum="1" maximum="1000" />
</p:inputText>
<p:message for="Qty" display="icon"/>
<p:commandButton value="add" update="display grid" actionListener="#{beanPerfectTable.adds()}" >
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:spacer height="30px;"/>
<p:outputPanel id="display">
<p:dataTable value="#{beanPerfectTable.items}" var="show" id="displayTable" editable="true" rowIndexVar="rowIndex">
<p:ajax event="rowEdit" listener="#{beanPerfectTable.onRowEdit}" update=":form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{beanPerfectTable.onRowCancel}" update=":form:msgs"/>
<p:columnGroup type="header">
<p:row>
<p:column headerText="No" style="width:10px"/>
<p:column headerText="Id"/>
<p:column headerText="Item"/>
<p:column headerText="Price"/>
<p:column headerText="Unit"/>
<p:column headerText="Qty"/>
<p:column colspan="2" headerText="acction"/>
</p:row>
</p:columnGroup>
<p:column style="width:10px">
#{rowIndex+1}
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.id}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.id}" style="width:100%" /></f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.item}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.item}" style="width:100%"/> </f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.price}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.price}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.unit}"/></f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{beanPerfectTable.var.unit}" style="width:100%">
<f:selectItems value="#{beanPerfectTable.units}" var="un" itemLabel="#{un}" itemValue="#{un}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.qty}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.qty}" style="width:100%"/> </f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:10px">
<p:commandButton icon="ui-icon-minusthick" update="displayTable" actionListener="#{beanPerfectTable.hapus(show)}"/>
</p:column>
<p:column style="width:10px">
<p:rowEditor />
</p:column>
<p:columnGroup type="footer">
<p:row>
<p:column colspan="5" footerText="Total :" style="text-align:right"/>
<p:column footerText="#{beanPerfectTable.tot}"/>
<p:column colspan="2"/>
</p:row>
</p:columnGroup>
</p:dataTable>
</p:outputPanel>
</h:form>
</h:body>
</h:head>
</html>
java<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<h:body>
<h:form id="form">
<p:messages id="msgs" autoUpdate="true" />
<p:panel header="Data Items" style="margin-buttom:10px">
<h:panelGrid id="grid" columns="3" cellpadding="5">
<h:outputLabel value="Id :" for="Id" />
<p:inputText id="Id" value="#{beanPerfectTable.var.id}" required="true" >
<f:validateLength minimum="5" maximum="5"/>
</p:inputText>
<p:message for="Id" display="icon"/>
<h:outputLabel value="Item :" for="Item" />
<p:inputText id="Item" value="#{beanPerfectTable.var.item}" required="true" placeholder="Rp.000.0"/>
<p:message for="Item" display="icon"/>
<h:outputLabel value="Price :" for="Price" />
<p:inputText id="Price" value="#{beanPerfectTable.var.price}">
<f:convertNumber type="currency" currencySymbol="Rp."/>
</p:inputText>
<p:message for="Price" display="icon"/>
<h:outputLabel value="Unit :" for="Unit" />
<p:selectOneMenu id="Unit" value="#{beanPerfectTable.var.unit}">
<f:selectItem itemLabel="Select One Menu" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{beanPerfectTable.units}"/>
</p:selectOneMenu>
<p:message for="Unit" display="icon"/>
<h:outputLabel value="Qty :" for="Qty" />
<p:inputText id="Qty" value="#{beanPerfectTable.var.qty}" >
<f:validateDoubleRange minimum="1" maximum="1000" />
</p:inputText>
<p:message for="Qty" display="icon"/>
<p:commandButton value="add" update="display grid" actionListener="#{beanPerfectTable.adds()}" >
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:spacer height="30px;"/>
<p:outputPanel id="display">
<p:dataTable value="#{beanPerfectTable.items}" var="show" id="displayTable" editable="true" rowIndexVar="rowIndex">
<p:ajax event="rowEdit" listener="#{beanPerfectTable.onRowEdit}" update=":form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{beanPerfectTable.onRowCancel}" update=":form:msgs"/>
<p:columnGroup type="header">
<p:row>
<p:column headerText="No" style="width:10px"/>
<p:column headerText="Id"/>
<p:column headerText="Item"/>
<p:column headerText="Price"/>
<p:column headerText="Unit"/>
<p:column headerText="Qty"/>
<p:column colspan="2" headerText="acction"/>
</p:row>
</p:columnGroup>
<p:column style="width:10px">
#{rowIndex+1}
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.id}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.id}" style="width:100%" /></f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.item}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.item}" style="width:100%"/> </f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.price}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.price}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.unit}"/></f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{beanPerfectTable.var.unit}" style="width:100%">
<f:selectItems value="#{beanPerfectTable.units}" var="un" itemLabel="#{un}" itemValue="#{un}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column >
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{show.qty}"/></f:facet>
<f:facet name="input"><p:inputText value="#{show.qty}" style="width:100%"/> </f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:10px">
<p:commandButton icon="ui-icon-minusthick" update="displayTable" actionListener="#{beanPerfectTable.hapus(show)}"/>
</p:column>
<p:column style="width:10px">
<p:rowEditor />
</p:column>
<p:columnGroup type="footer">
<p:row>
<p:column colspan="5" footerText="Total :" style="text-align:right"/>
<p:column footerText="#{beanPerfectTable.tot}"/>
<p:column colspan="2"/>
</p:row>
</p:columnGroup>
</p:dataTable>
</p:outputPanel>
</h:form>
</h:body>
</h:head>
</html>
package list;
import dua.variabels;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class proses {
private variabels variabel = new variabels();
private static List<variabels> bundel = new ArrayList<variabels>();
public variabels getVariabel() {
return variabel;
}
public void setVariabel(variabels variabel) {
this.variabel = variabel;
}
//pengulangan input
public List<variabels> getBundel() {
return bundel;
}
//penerapan set berkali-kali
public void setBundel(List<variabels> bundel) {
proses.bundel = bundel;
}
//fungsi untuk menampilkan hasil set variabel
public void hasil(){
proses.bundel.add(this.variabel);
}
//fungsi untuk menghapus dibidik berdasarkan vairabel yang nantinya disalurkan di xhtml
//variabel yang akan dihapus
public void hapus(variabels dell){
proses.bundel.remove(dell);
}
}
javaimport dua.variabels;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class proses {
private variabels variabel = new variabels();
private static List<variabels> bundel = new ArrayList<variabels>();
public variabels getVariabel() {
return variabel;
}
public void setVariabel(variabels variabel) {
this.variabel = variabel;
}
//pengulangan input
public List<variabels> getBundel() {
return bundel;
}
//penerapan set berkali-kali
public void setBundel(List<variabels> bundel) {
proses.bundel = bundel;
}
//fungsi untuk menampilkan hasil set variabel
public void hasil(){
proses.bundel.add(this.variabel);
}
//fungsi untuk menghapus dibidik berdasarkan vairabel yang nantinya disalurkan di xhtml
//variabel yang akan dihapus
public void hapus(variabels dell){
proses.bundel.remove(dell);
}
}
package dua;
public class variabels {
private String no;
private String nama;
private String Jns_kel;
public String getNo() {
return no;
}
public String getNama() {
return nama;
}
public void setNama(String nama) {
this.nama = nama;
}
public String getJns_kel() {
return Jns_kel;
}
public void setJns_kel(String jns_kel) {
this.Jns_kel = jns_kel;
}
public void setNo(String no) {
this.no = no;
}
}
public class variabels {
private String no;
private String nama;
private String Jns_kel;
public String getNo() {
return no;
}
public String getNama() {
return nama;
}
public void setNama(String nama) {
this.nama = nama;
}
public String getJns_kel() {
return Jns_kel;
}
public void setJns_kel(String jns_kel) {
this.Jns_kel = jns_kel;
}
public void setNo(String no) {
this.no = no;
}
}
No comments: