primefaces-spring
Langkah - langkah membuat project dinamic web server :
1. persiapkan library
2. siapkan file xml dan faces-config.xml
coding .xml
3. setelah buat folder classes dan file springtest.xhtml
code springtest.xhtml
4. buat folder link
5. buat BeanLoader.java
5. buat mapper.java
1. persiapkan library
2. siapkan file xml dan faces-config.xml
coding .xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MAHASISWA</display-name>
<welcome-file-list>
<welcome-file>MAHASISWA.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.sun.faces.writeStateAtFormEnd</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>sunny</param-value>
</context-param>
</web-app>
coding .faces-config.xhtml<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MAHASISWA</display-name>
<welcome-file-list>
<welcome-file>MAHASISWA.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.sun.faces.writeStateAtFormEnd</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>sunny</param-value>
</context-param>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
</faces-config>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
</faces-config>
3. setelah buat folder classes dan file springtest.xhtml
code springtest.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- initialization for data source -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/MAHASISWA" />
<property name="username" value="postgres" />
<property name="password" value="nunmufida" />
</bean>
<!-- Definition for studentJDBCTemplate bean -->
<bean id="MahasiswaDao" class="com.nurdin.test.spring.dao.MahasiswaDao">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- initialization for data source -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/MAHASISWA" />
<property name="username" value="postgres" />
<property name="password" value="nunmufida" />
</bean>
<!-- Definition for studentJDBCTemplate bean -->
<bean id="MahasiswaDao" class="com.nurdin.test.spring.dao.MahasiswaDao">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
4. buat folder link
5. buat BeanLoader.java
package com.nurdin.test.spring.util;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BeanLoader {
/**
* Load bean.
*
* @param bean
* the bean
* @return the object
*/
public static Object loadBean(String bean) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"springtest.xml");
return context.getBean(bean);
}
}
5. buat model.javaimport org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BeanLoader {
/**
* Load bean.
*
* @param bean
* the bean
* @return the object
*/
public static Object loadBean(String bean) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"springtest.xml");
return context.getBean(bean);
}
}
package com.nurdin.test.spring.mapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.nurdin.test.spring.model.MahasiswaBook;
public class MahasiswaMapper implements RowMapper<MahasiswaBook> {
public MahasiswaBook mapRow(ResultSet rs, int rowNum) throws SQLException {
MahasiswaBook mahasiswabook = new MahasiswaBook();
mahasiswabook.setId(rs.getInt("id"));
mahasiswabook.setKode_mt_kuliah(rs.getString("kode_mt_kuliah"));
mahasiswabook.setMt_kuliah(rs.getString("mt_kuliah"));
mahasiswabook.setSks(rs.getInt("sks"));
return mahasiswabook;
}
}
5. buat dao.javaimport java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.nurdin.test.spring.model.MahasiswaBook;
public class MahasiswaMapper implements RowMapper<MahasiswaBook> {
public MahasiswaBook mapRow(ResultSet rs, int rowNum) throws SQLException {
MahasiswaBook mahasiswabook = new MahasiswaBook();
mahasiswabook.setId(rs.getInt("id"));
mahasiswabook.setKode_mt_kuliah(rs.getString("kode_mt_kuliah"));
mahasiswabook.setMt_kuliah(rs.getString("mt_kuliah"));
mahasiswabook.setSks(rs.getInt("sks"));
return mahasiswabook;
}
}
package com.nurdin.test.spring.dao;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import com.nurdin.test.spring.mapper.MahasiswaMapper;
import com.nurdin.test.spring.model.MahasiswaBook;
public class MahasiswaDao {
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource ds) {
this.dataSource = ds;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public DataSource getDataSource() {
return dataSource;
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<MahasiswaBook> getAllMahasiswaBook() {
String sql = "SELECT * FROM public.matkul";
List<MahasiswaBook> addbook = jdbcTemplate.query(sql,
new MahasiswaMapper());
return addbook;
}
public int save(MahasiswaBook mahasiswabook) {
String query = "INSERT INTO public.matkul("
+ "kode_mt_kuliah, mt_kuliah, sks) " + "VALUES (?, ?, ?)";
int result = jdbcTemplate.update(query,
mahasiswabook.getKode_mt_kuliah(),
mahasiswabook.getMt_kuliah(), mahasiswabook.getSks());
return result;
}
public int updatedao(MahasiswaBook mahasiswabookupdatedao) {
String query = "UPDATE public.matkul SET " + " kode_mt_kuliah=?,"
+ " mt_kuliah=?," + " sks=?" + " where id=?";
int result = jdbcTemplate
.update(query, mahasiswabookupdatedao.getKode_mt_kuliah(),
mahasiswabookupdatedao.getMt_kuliah(),
mahasiswabookupdatedao.getSks(),
mahasiswabookupdatedao.getId());
return result;
}
public int deleteddao(MahasiswaBook mahasiswabookdelete) {
String query = "DELETE from public.matkul " + " where id=?";
int result = jdbcTemplate.update(query, mahasiswabookdelete.getId());
return result;
}
}
5. buat bl.javaimport java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import com.nurdin.test.spring.mapper.MahasiswaMapper;
import com.nurdin.test.spring.model.MahasiswaBook;
public class MahasiswaDao {
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource ds) {
this.dataSource = ds;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public DataSource getDataSource() {
return dataSource;
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<MahasiswaBook> getAllMahasiswaBook() {
String sql = "SELECT * FROM public.matkul";
List<MahasiswaBook> addbook = jdbcTemplate.query(sql,
new MahasiswaMapper());
return addbook;
}
public int save(MahasiswaBook mahasiswabook) {
String query = "INSERT INTO public.matkul("
+ "kode_mt_kuliah, mt_kuliah, sks) " + "VALUES (?, ?, ?)";
int result = jdbcTemplate.update(query,
mahasiswabook.getKode_mt_kuliah(),
mahasiswabook.getMt_kuliah(), mahasiswabook.getSks());
return result;
}
public int updatedao(MahasiswaBook mahasiswabookupdatedao) {
String query = "UPDATE public.matkul SET " + " kode_mt_kuliah=?,"
+ " mt_kuliah=?," + " sks=?" + " where id=?";
int result = jdbcTemplate
.update(query, mahasiswabookupdatedao.getKode_mt_kuliah(),
mahasiswabookupdatedao.getMt_kuliah(),
mahasiswabookupdatedao.getSks(),
mahasiswabookupdatedao.getId());
return result;
}
public int deleteddao(MahasiswaBook mahasiswabookdelete) {
String query = "DELETE from public.matkul " + " where id=?";
int result = jdbcTemplate.update(query, mahasiswabookdelete.getId());
return result;
}
}
package com.nurdin.test.spring.bl;
import java.util.List;
import com.nurdin.test.spring.dao.MahasiswaDao;
import com.nurdin.test.spring.model.MahasiswaBook;
import com.nurdin.test.spring.util.BeanLoader;
public class MahasiswaBL {
private MahasiswaDao daoImpl = (MahasiswaDao) BeanLoader
.loadBean("MahasiswaDao");
public List<MahasiswaBook> getAllData() {
return daoImpl.getAllMahasiswaBook();
}
public int save(MahasiswaBook mahasiswaBook) {
return daoImpl.save(mahasiswaBook);
}
public int update(MahasiswaBook mahasiswaBookupdate) {
return daoImpl.updatedao(mahasiswaBookupdate);
}
public int deleted(MahasiswaBook mahasiswaBookdeleted) {
return daoImpl.deleteddao(mahasiswaBookdeleted);
}
}
5. buat bean.javaimport java.util.List;
import com.nurdin.test.spring.dao.MahasiswaDao;
import com.nurdin.test.spring.model.MahasiswaBook;
import com.nurdin.test.spring.util.BeanLoader;
public class MahasiswaBL {
private MahasiswaDao daoImpl = (MahasiswaDao) BeanLoader
.loadBean("MahasiswaDao");
public List<MahasiswaBook> getAllData() {
return daoImpl.getAllMahasiswaBook();
}
public int save(MahasiswaBook mahasiswaBook) {
return daoImpl.save(mahasiswaBook);
}
public int update(MahasiswaBook mahasiswaBookupdate) {
return daoImpl.updatedao(mahasiswaBookupdate);
}
public int deleted(MahasiswaBook mahasiswaBookdeleted) {
return daoImpl.deleteddao(mahasiswaBookdeleted);
}
}
package com.nurdin.test.spring.bean;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RowEditEvent;
import sun.util.calendar.BaseCalendar.Date;
import com.nurdin.test.spring.bl.MahasiswaBL;
import com.nurdin.test.spring.bl.PerkuliahanBL;
import com.nurdin.test.spring.model.MahasiswaBook;
import com.nurdin.test.spring.model.PerkuliahanBook;
@ManagedBean
@ViewScoped
public class SpringTestBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<MahasiswaBook> listMahasiswaBook;
private List<PerkuliahanBook> listperkuliahanBook;
private MahasiswaBook mahasiswabook = new MahasiswaBook();
private PerkuliahanBook perkuliahanbook = new PerkuliahanBook();
private MahasiswaBook mahasiswabookrow = new MahasiswaBook();
private MahasiswaBL mahasiswaBL = new MahasiswaBL();
private PerkuliahanBL perkuliahanBL = new PerkuliahanBL();
private Date dateofbirth;
private static int msg;
@PostConstruct
public void init() {
setListMahasiswaBook(mahasiswaBL.getAllData());
setListperkuliahanBook(perkuliahanBL.getAllData());
}
public void save() {
int result = mahasiswaBL.save(mahasiswabook);
if (result > 0) {
msg = msg + 1;
} else {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Faild",
"Data was inputed "));
}
}
public void growl() {
if (msg > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful",
"Data was inputed "));
msg = 0;
}
}
public void onRowEdit(RowEditEvent event) {
MahasiswaBook mahasiswabookupdate = (MahasiswaBook) event.getObject();
System.out.println(mahasiswabookupdate);
int results = mahasiswaBL.update(mahasiswabookupdate);
if (results > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful",
"Data was updated "));
}
}
public void onRowCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Edit Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void delete(MahasiswaBook dell) {
listMahasiswaBook.remove(dell);
int results = mahasiswaBL.deleted(dell);
if (results > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful",
"Data was Deleted"));
}
}
public void saveperkuliahan(){
int result = perkuliahanBL.save(perkuliahanbook);
if (result > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Success",
"Data was inputed "));
} else {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Faild",
"Data was faild to inputed "));
}
}
public List<MahasiswaBook> getListMahasiswaBook() {
return listMahasiswaBook;
}
public void setListMahasiswaBook(List<MahasiswaBook> listMahasiswaBook) {
this.listMahasiswaBook = listMahasiswaBook;
}
public List<PerkuliahanBook> getListperkuliahanBook() {
return listperkuliahanBook;
}
public void setListperkuliahanBook(List<PerkuliahanBook> listperkuliahanBook) {
this.listperkuliahanBook = listperkuliahanBook;
}
public MahasiswaBook getMahasiswabook() {
return mahasiswabook;
}
public void setMahasiswabook(MahasiswaBook mahasiswabook) {
this.mahasiswabook = mahasiswabook;
}
public Date getDateofbirth() {
return dateofbirth;
}
public void setDateofbirth(Date dateofbirth) {
this.dateofbirth = dateofbirth;
}
public PerkuliahanBook getPerkuliahanbook() {
return perkuliahanbook;
}
public void setPerkuliahanbook(PerkuliahanBook perkuliahanbook) {
this.perkuliahanbook = perkuliahanbook;
}
public int getMsg() {
return msg;
}
public void setMsg(int msg) {
SpringTestBean.msg = msg;
}
public MahasiswaBook getMahasiswabookrow() {
return mahasiswabookrow;
}
}
5. buat mahasiswa.xhtmlimport java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RowEditEvent;
import sun.util.calendar.BaseCalendar.Date;
import com.nurdin.test.spring.bl.MahasiswaBL;
import com.nurdin.test.spring.bl.PerkuliahanBL;
import com.nurdin.test.spring.model.MahasiswaBook;
import com.nurdin.test.spring.model.PerkuliahanBook;
@ManagedBean
@ViewScoped
public class SpringTestBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<MahasiswaBook> listMahasiswaBook;
private List<PerkuliahanBook> listperkuliahanBook;
private MahasiswaBook mahasiswabook = new MahasiswaBook();
private PerkuliahanBook perkuliahanbook = new PerkuliahanBook();
private MahasiswaBook mahasiswabookrow = new MahasiswaBook();
private MahasiswaBL mahasiswaBL = new MahasiswaBL();
private PerkuliahanBL perkuliahanBL = new PerkuliahanBL();
private Date dateofbirth;
private static int msg;
@PostConstruct
public void init() {
setListMahasiswaBook(mahasiswaBL.getAllData());
setListperkuliahanBook(perkuliahanBL.getAllData());
}
public void save() {
int result = mahasiswaBL.save(mahasiswabook);
if (result > 0) {
msg = msg + 1;
} else {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Faild",
"Data was inputed "));
}
}
public void growl() {
if (msg > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful",
"Data was inputed "));
msg = 0;
}
}
public void onRowEdit(RowEditEvent event) {
MahasiswaBook mahasiswabookupdate = (MahasiswaBook) event.getObject();
System.out.println(mahasiswabookupdate);
int results = mahasiswaBL.update(mahasiswabookupdate);
if (results > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful",
"Data was updated "));
}
}
public void onRowCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Edit Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void delete(MahasiswaBook dell) {
listMahasiswaBook.remove(dell);
int results = mahasiswaBL.deleted(dell);
if (results > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful",
"Data was Deleted"));
}
}
public void saveperkuliahan(){
int result = perkuliahanBL.save(perkuliahanbook);
if (result > 0) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Success",
"Data was inputed "));
} else {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Faild",
"Data was faild to inputed "));
}
}
public List<MahasiswaBook> getListMahasiswaBook() {
return listMahasiswaBook;
}
public void setListMahasiswaBook(List<MahasiswaBook> listMahasiswaBook) {
this.listMahasiswaBook = listMahasiswaBook;
}
public List<PerkuliahanBook> getListperkuliahanBook() {
return listperkuliahanBook;
}
public void setListperkuliahanBook(List<PerkuliahanBook> listperkuliahanBook) {
this.listperkuliahanBook = listperkuliahanBook;
}
public MahasiswaBook getMahasiswabook() {
return mahasiswabook;
}
public void setMahasiswabook(MahasiswaBook mahasiswabook) {
this.mahasiswabook = mahasiswabook;
}
public Date getDateofbirth() {
return dateofbirth;
}
public void setDateofbirth(Date dateofbirth) {
this.dateofbirth = dateofbirth;
}
public PerkuliahanBook getPerkuliahanbook() {
return perkuliahanbook;
}
public void setPerkuliahanbook(PerkuliahanBook perkuliahanbook) {
this.perkuliahanbook = perkuliahanbook;
}
public int getMsg() {
return msg;
}
public void setMsg(int msg) {
SpringTestBean.msg = msg;
}
public MahasiswaBook getMahasiswabookrow() {
return mahasiswabookrow;
}
}
<!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"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
<h:body>
<h:form id="form">
<p:panel id="panel" style="margin-bottom:10px;">
<p:growl id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<f:event listener="#{springTestBean.growl}" type="preRenderView"></f:event>
<p:button value="Add New Data" outcome="ADDMAHASISWA"></p:button>
<p:dataTable var="listData" editable="true" paginator="true"
rowClasses="list-row" rows="10"
value="#{springTestBean.listMahasiswaBook}"
paginatorPosition="bottom" rowKey="#{listData.id}"
selection="#{springTestBean.mahasiswabookrow}"
selectionMode="single">
<p:ajax event="rowEdit" listener="#{springTestBean.onRowEdit}"
update=":form:messages" />
<p:ajax event="rowEditCancel"
listener="#{springTestBean.onRowCancel}" update=":form:messages" />
<p:columnGroup type="header">
<p:row>
<p:column headerText="Kode Mata Kulilah"></p:column>
<p:column headerText="Mata Kuliah"></p:column>
<p:column headerText="Sks"></p:column>
<p:column colspan="3" headerText="action" />
</p:row>
</p:columnGroup>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listData.kode_mt_kuliah}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listData.kode_mt_kuliah}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listData.mt_kuliah}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listData.mt_kuliah}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listData.sks}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listData.sks}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:20px">
<p:commandButton icon="ui-icon-disk" onclick="confirmation.show()">
<f:setPropertyActionListener value="#{listData}"
target="#{springTestBean.mahasiswabook}" />
</p:commandButton>
</p:column>
<p:column style="width:20px">
<p:rowEditor />
</p:column>
<p:column style="width:20px">
<p:commandLink value="add"
style="font-size:15px; font-style:italic"
onclick="perkuliahan.show()">
<f:setPropertyActionListener value="#{listData}"
target="#{springTestBean.mahasiswabook}" />
</p:commandLink>
</p:column>
</p:dataTable>
<p:confirmDialog message="Are you sure to delete?"
header="Confirmation" severity="alert" widgetVar="confirmation">
<p:commandButton value="Yes"
actionListener="#{springTestBean.delete(springTestBean.mahasiswabook)}"
icon="ui-icon-check" onclick="confirmation.hide()"
update="@(form)" />
<p:commandButton value="Not" onclick="confirmation.hide()"
type="button" />
</p:confirmDialog>
<p:dialog header="Add perkuliahan" widgetVar="perkuliahan"
modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:panel style="margin-buttom:10px">
<h:panelGrid columns="2">
<p:outputLabel for="idFK" value="idFK"/>
<p:inputText id="idFK" value="#{springTestBean.mahasiswabook}"/>
<p:outputLabel for="datetime" value="Jadwal :" />
<p:calendar id="datetime" value="#{calendarView.date10}" pattern="MM/dd/yyyy HH:mm:ss" />
<h:outputLabel value="Kode Ruangan :" for="koderuangan" />
<p:inputText id="koderuangan" value="" />
<h:outputLabel value="Kode Dosen :" for="kodedosen" />
<p:inputText id="kodedosen" value="" />
<p:commandButton value="add" />
</h:panelGrid>
</p:panel>
<p:spacer height="30px;" />
<p:outputPanel>
<p:dataTable var="listDataDetail" editable="true" paginator="true"
rowClasses="list-row" rows="10"
value="#{springTestBean.listperkuliahanBook}"
paginatorPosition="bottom" >
<p:ajax event="rowEdit" />
<p:ajax event="rowEditCancel" />
<p:columnGroup type="header">
<p:row>
<p:column headerText="No" style="width:10px" />
<p:column headerText="id mata kuliah" />
<p:column headerText="jadwal" />
<p:column headerText="Kode Ruangan" />
<p:column headerText="Kode Dosen" />
<p:column colspan="2" headerText="acction" />
</p:row>
</p:columnGroup>
<p:column style="width:10px">
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.idFK}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listDataDetail.idFK}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.jadwal}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listDataDetail.jadwal}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.kode_ruangan}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{listDataDetail.kode_ruangan}" style="width:100%">
<f:selectItems />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.kode_dosen}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{listDataDetail.kode_dosen}" style="width:100%">
<f:selectItems />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:10px">
<p:commandButton icon="ui-icon-minusthick" />
</p:column>
<p:column style="width:10px">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
</p:panel>
</h:form>
</h:body>
</h:head>
</html>
5. buat addmahasiswa.xhtml<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"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
<h:body>
<h:form id="form">
<p:panel id="panel" style="margin-bottom:10px;">
<p:growl id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<f:event listener="#{springTestBean.growl}" type="preRenderView"></f:event>
<p:button value="Add New Data" outcome="ADDMAHASISWA"></p:button>
<p:dataTable var="listData" editable="true" paginator="true"
rowClasses="list-row" rows="10"
value="#{springTestBean.listMahasiswaBook}"
paginatorPosition="bottom" rowKey="#{listData.id}"
selection="#{springTestBean.mahasiswabookrow}"
selectionMode="single">
<p:ajax event="rowEdit" listener="#{springTestBean.onRowEdit}"
update=":form:messages" />
<p:ajax event="rowEditCancel"
listener="#{springTestBean.onRowCancel}" update=":form:messages" />
<p:columnGroup type="header">
<p:row>
<p:column headerText="Kode Mata Kulilah"></p:column>
<p:column headerText="Mata Kuliah"></p:column>
<p:column headerText="Sks"></p:column>
<p:column colspan="3" headerText="action" />
</p:row>
</p:columnGroup>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listData.kode_mt_kuliah}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listData.kode_mt_kuliah}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listData.mt_kuliah}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listData.mt_kuliah}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listData.sks}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listData.sks}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:20px">
<p:commandButton icon="ui-icon-disk" onclick="confirmation.show()">
<f:setPropertyActionListener value="#{listData}"
target="#{springTestBean.mahasiswabook}" />
</p:commandButton>
</p:column>
<p:column style="width:20px">
<p:rowEditor />
</p:column>
<p:column style="width:20px">
<p:commandLink value="add"
style="font-size:15px; font-style:italic"
onclick="perkuliahan.show()">
<f:setPropertyActionListener value="#{listData}"
target="#{springTestBean.mahasiswabook}" />
</p:commandLink>
</p:column>
</p:dataTable>
<p:confirmDialog message="Are you sure to delete?"
header="Confirmation" severity="alert" widgetVar="confirmation">
<p:commandButton value="Yes"
actionListener="#{springTestBean.delete(springTestBean.mahasiswabook)}"
icon="ui-icon-check" onclick="confirmation.hide()"
update="@(form)" />
<p:commandButton value="Not" onclick="confirmation.hide()"
type="button" />
</p:confirmDialog>
<p:dialog header="Add perkuliahan" widgetVar="perkuliahan"
modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:panel style="margin-buttom:10px">
<h:panelGrid columns="2">
<p:outputLabel for="idFK" value="idFK"/>
<p:inputText id="idFK" value="#{springTestBean.mahasiswabook}"/>
<p:outputLabel for="datetime" value="Jadwal :" />
<p:calendar id="datetime" value="#{calendarView.date10}" pattern="MM/dd/yyyy HH:mm:ss" />
<h:outputLabel value="Kode Ruangan :" for="koderuangan" />
<p:inputText id="koderuangan" value="" />
<h:outputLabel value="Kode Dosen :" for="kodedosen" />
<p:inputText id="kodedosen" value="" />
<p:commandButton value="add" />
</h:panelGrid>
</p:panel>
<p:spacer height="30px;" />
<p:outputPanel>
<p:dataTable var="listDataDetail" editable="true" paginator="true"
rowClasses="list-row" rows="10"
value="#{springTestBean.listperkuliahanBook}"
paginatorPosition="bottom" >
<p:ajax event="rowEdit" />
<p:ajax event="rowEditCancel" />
<p:columnGroup type="header">
<p:row>
<p:column headerText="No" style="width:10px" />
<p:column headerText="id mata kuliah" />
<p:column headerText="jadwal" />
<p:column headerText="Kode Ruangan" />
<p:column headerText="Kode Dosen" />
<p:column colspan="2" headerText="acction" />
</p:row>
</p:columnGroup>
<p:column style="width:10px">
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.idFK}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listDataDetail.idFK}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.jadwal}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listDataDetail.jadwal}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.kode_ruangan}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{listDataDetail.kode_ruangan}" style="width:100%">
<f:selectItems />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listDataDetail.kode_dosen}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{listDataDetail.kode_dosen}" style="width:100%">
<f:selectItems />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:10px">
<p:commandButton icon="ui-icon-minusthick" />
</p:column>
<p:column style="width:10px">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
</p:panel>
</h:form>
</h:body>
</h:head>
</html>
<!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"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
<h:body>
<h:form>
<p:panel id="panel" style="margin-bottom:10px;">
<p:growl id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<h:panelGrid columns="3" cellpadding="5">
<p:outputLabel for="kodemtkuliah" value="Kode Mata kuliah:" />
<p:inputText id="kodemtkuliah"
value="#{springTestBean.mahasiswabook.kode_mt_kuliah}">
</p:inputText>
<p:message for="kodemtkuliah" display="icon" />
<p:outputLabel for="mtkuliah" value="Mata kuliah:" />
<p:inputText id="mtkuliah"
value="#{springTestBean.mahasiswabook.mt_kuliah}">
</p:inputText>
<p:message for="mtkuliah" display="icon" />
<h:outputLabel for="sks" value="Sks:" />
<p:inputText id="sks" value="#{springTestBean.mahasiswabook.sks}">
</p:inputText>
<p:message for="sks" display="icon" />
<!-- <p:outputLabel for="gender" value="Gender:" />
<p:selectOneRadio id="gender">
<f:selectItem itemLabel="Male" itemValue="male" />
<f:selectItem itemLabel="Female" itemValue="female" />
</p:selectOneRadio>
<p:outputLabel for="dateofbirth" value="Date of Birth:" />
<p:calendar id="dateofbirth"
pattern="dd-MM-yyyy" mask="true" yearRange="c-70:c+5" navigator="true"/> -->
</h:panelGrid>
<h:panelGrid columns="3" cellpadding="5">
<p:commandButton value="Save" icon="ui-icon-disk"
onclick="confirmation.show()" />
<p:confirmDialog message="Are you sure to save?"
header="Confirmation" severity="alert" widgetVar="confirmation">
<p:commandButton value="Yes"
actionListener="#{springTestBean.save}"
action="MAHASISWA?faces-redirect=true" icon="ui-icon-check"
oncomplete="confirmation.hide()" />
<p:commandButton value="Not" onclick="confirmation.hide()"
type="button" />
</p:confirmDialog>
<p:button value="Cancel" icon="ui-icon-minus"
onfocus="confirmation1.show()" />
<p:confirmDialog message="Are you sure to cancel?"
header="Confirmation1" widgetVar="confirmation1">
<p:button value="Yes" oncomplete="confirmation1.hide()"
outcome="MAHASISWA" icon="ui-icon-check" />
<p:button value="Not" onclick="confirmation1.hide()" />
</p:confirmDialog>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</h:head>
</html>
<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"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
<h:body>
<h:form>
<p:panel id="panel" style="margin-bottom:10px;">
<p:growl id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<h:panelGrid columns="3" cellpadding="5">
<p:outputLabel for="kodemtkuliah" value="Kode Mata kuliah:" />
<p:inputText id="kodemtkuliah"
value="#{springTestBean.mahasiswabook.kode_mt_kuliah}">
</p:inputText>
<p:message for="kodemtkuliah" display="icon" />
<p:outputLabel for="mtkuliah" value="Mata kuliah:" />
<p:inputText id="mtkuliah"
value="#{springTestBean.mahasiswabook.mt_kuliah}">
</p:inputText>
<p:message for="mtkuliah" display="icon" />
<h:outputLabel for="sks" value="Sks:" />
<p:inputText id="sks" value="#{springTestBean.mahasiswabook.sks}">
</p:inputText>
<p:message for="sks" display="icon" />
<!-- <p:outputLabel for="gender" value="Gender:" />
<p:selectOneRadio id="gender">
<f:selectItem itemLabel="Male" itemValue="male" />
<f:selectItem itemLabel="Female" itemValue="female" />
</p:selectOneRadio>
<p:outputLabel for="dateofbirth" value="Date of Birth:" />
<p:calendar id="dateofbirth"
pattern="dd-MM-yyyy" mask="true" yearRange="c-70:c+5" navigator="true"/> -->
</h:panelGrid>
<h:panelGrid columns="3" cellpadding="5">
<p:commandButton value="Save" icon="ui-icon-disk"
onclick="confirmation.show()" />
<p:confirmDialog message="Are you sure to save?"
header="Confirmation" severity="alert" widgetVar="confirmation">
<p:commandButton value="Yes"
actionListener="#{springTestBean.save}"
action="MAHASISWA?faces-redirect=true" icon="ui-icon-check"
oncomplete="confirmation.hide()" />
<p:commandButton value="Not" onclick="confirmation.hide()"
type="button" />
</p:confirmDialog>
<p:button value="Cancel" icon="ui-icon-minus"
onfocus="confirmation1.show()" />
<p:confirmDialog message="Are you sure to cancel?"
header="Confirmation1" widgetVar="confirmation1">
<p:button value="Yes" oncomplete="confirmation1.hide()"
outcome="MAHASISWA" icon="ui-icon-check" />
<p:button value="Not" onclick="confirmation1.hide()" />
</p:confirmDialog>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</h:head>
</html>
No comments: