TempInputRow
file 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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<h:body>
<h:form id="form">
<p:growl id="growl" showDetail="true" sticky="true" />
<h:panelGrid columns="3">
<h:panelGrid>
<p:commandButton value="add" update="display" action="#{bean.action()}" />
<p:scrollPanel mode="native" style="width:400px;height:300px;border:0px">
<p:panelGrid style="margin-top:20px" id="display">
<f:facet name="header">
<p:row>
<p:column >
<p:outputLabel value="No" />
</p:column>
<p:column >
<p:outputLabel value="Nama" />
</p:column>
</p:row>
</f:facet>
<c:forEach var="i" begin="1" end="#{bean.tambah}">
<p:row>
<p:column >
#{i}
</p:column>
<p:column>
<p:inputText value="#{bean.listData[i]}" />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-minusthick" title="Icon Only" action="#{bean.TempDel(i)}" update="display" />
</p:column>
</p:row>
</c:forEach>
</p:panelGrid>
</p:scrollPanel>
</h:panelGrid>
<p:scrollPanel mode="native" style="width:500px;height:300px;border:0px">
<p:commandButton value="Submit" update="Sdisplay growl" action="#{bean.submitForm()}" />
<p:dataTable id="Sdisplay" value="#{bean.listDataTable}" var="show" rowIndexVar="rowIndex" >
<p:column headerText="No">
#{rowIndex + 1}
</p:column>
<p:column headerText="Nama" style="width: 300px;">
<h:outputText value="#{show}" />
</p:column>
<p:column>
<p:commandButton update="Sdisplay" value="dell" action="#{bean.TempDel2(show)}">
</p:commandButton>
</p:column>
</p:dataTable>
</p:scrollPanel>
</h:panelGrid>
</h:form>
</h:body>
</h:head>
</html>
file 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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<h:body>
<h:form id="form">
<p:growl id="growl" showDetail="true" sticky="true" />
<h:panelGrid columns="3">
<h:panelGrid>
<p:commandButton value="add" update="display" action="#{bean.action()}" />
<p:scrollPanel mode="native" style="width:400px;height:300px;border:0px">
<p:panelGrid style="margin-top:20px" id="display">
<f:facet name="header">
<p:row>
<p:column >
<p:outputLabel value="No" />
</p:column>
<p:column >
<p:outputLabel value="Nama" />
</p:column>
</p:row>
</f:facet>
<c:forEach var="i" begin="1" end="#{bean.tambah}">
<p:row>
<p:column >
#{i}
</p:column>
<p:column>
<p:inputText value="#{bean.listData[i]}" />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-minusthick" title="Icon Only" action="#{bean.TempDel(i)}" update="display" />
</p:column>
</p:row>
</c:forEach>
</p:panelGrid>
</p:scrollPanel>
</h:panelGrid>
<p:scrollPanel mode="native" style="width:500px;height:300px;border:0px">
<p:commandButton value="Submit" update="Sdisplay growl" action="#{bean.submitForm()}" />
<p:dataTable id="Sdisplay" value="#{bean.listDataTable}" var="show" rowIndexVar="rowIndex" >
<p:column headerText="No">
#{rowIndex + 1}
</p:column>
<p:column headerText="Nama" style="width: 300px;">
<h:outputText value="#{show}" />
</p:column>
<p:column>
<p:commandButton update="Sdisplay" value="dell" action="#{bean.TempDel2(show)}">
</p:commandButton>
</p:column>
</p:dataTable>
</p:scrollPanel>
</h:panelGrid>
</h:form>
</h:body>
</h:head>
</html>
package list;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
@ManagedBean(name = "bean")
public class BeanTemInputRow {
private static int tambah=1;
private static List<String> listDataTable = new ArrayList<String>();
private static String[] listData = new String[10];
@PostConstruct
public void init(){
}
public void action(){
tambah= tambah+1;
listData[tambah] = "";
}
//for delete
//end for delete
public void TempDel(Byte i){
int intTemp = i;
List<String> list = new ArrayList<String>(Arrays.asList(listData));
list.remove(intTemp);
listData = list.toArray(listData);
tambah=tambah-1;
}
public void TempDel2(String dell){
listDataTable.remove(dell);
}
//submit
public void submitForm(){
for(int i=1;i<=listData.length;i++)
{
if(null!=listData[i]){
listDataTable.add(listData[i]);
}else
break;
}
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful", "Data was inputed " + tambah) );
}
//declaration
public int getTambah() {
return tambah;
}
public void setTambah(int tambah) {
BeanTemInputRow.tambah = tambah;
}
public List<String> getListDataTable() {
return listDataTable;
}
public void setListDataTable(List<String> listDataTable) {
BeanTemInputRow.listDataTable = listDataTable;
}
public String[] getListData() {
return listData;
}
public void setListData(String[] listData) {
BeanTemInputRow.listData = listData;
}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
@ManagedBean(name = "bean")
public class BeanTemInputRow {
private static int tambah=1;
private static List<String> listDataTable = new ArrayList<String>();
private static String[] listData = new String[10];
@PostConstruct
public void init(){
}
public void action(){
tambah= tambah+1;
listData[tambah] = "";
}
//for delete
//end for delete
public void TempDel(Byte i){
int intTemp = i;
List<String> list = new ArrayList<String>(Arrays.asList(listData));
list.remove(intTemp);
listData = list.toArray(listData);
tambah=tambah-1;
}
public void TempDel2(String dell){
listDataTable.remove(dell);
}
//submit
public void submitForm(){
for(int i=1;i<=listData.length;i++)
{
if(null!=listData[i]){
listDataTable.add(listData[i]);
}else
break;
}
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful", "Data was inputed " + tambah) );
}
//declaration
public int getTambah() {
return tambah;
}
public void setTambah(int tambah) {
BeanTemInputRow.tambah = tambah;
}
public List<String> getListDataTable() {
return listDataTable;
}
public void setListDataTable(List<String> listDataTable) {
BeanTemInputRow.listDataTable = listDataTable;
}
public String[] getListData() {
return listData;
}
public void setListData(String[] listData) {
BeanTemInputRow.listData = listData;
}
}
No comments: