最新做的demo -- ejb3.0,a4j

2019-04-15 13:41发布

以下是本人做的demo

[img]http://hiphotos.baidu.com/kennylin2008/pic/item/2bd2381b420049c6ac6e75b0.jpg[/img]

[img]http://hiphotos.baidu.com/kennylin2008/pic/item/a5125e8f87c1c6fdf11f3611.jpg[/img]



xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:richfaces="http://richfaces.ajax4jsf.org/rich"
xmlns:c="http://java.sun.com/jstl/core">




Type



























value="read" />























































#{item.name}







close










/************************Back Bean ******************///

**********************************************
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.oak.jsfcn.view.bean.page;

import java.util.List;
import javax.faces.event.ActionEvent;
import org.oak.jsfcn.server.entity.Type;
import org.oak.jsfcn.server.session.admin.TypeRemote;

/**
*
* @author KennyLin
*/
public class TypePage extends Page {

private List types;
private Type type;
private String selectedItem = "init";

/**
* page
*
*/
public TypePage() {
System.out.println(this.getClass().getName() + " TypePage init ...");
}

@Override
public void init() {
TypeRemote typeRemote = serviceLocator.getTypeRemote();
types = typeRemote.findAll();
}

public void editSetup(ActionEvent e) {
System.out.println(this.getClass().getName() + " editSetup ...");
type = (Type) getDataTable().getRowData();
include.setViewId("pop/typeEdit.xhtml");
}

public void edit(ActionEvent e) {
System.out.println(this.getClass().getName() + " edit ...");
TypeRemote typeRemote = serviceLocator.getTypeRemote();
typeRemote.merge(type);
init();
}

public void createSetup(ActionEvent e) {
System.out.println(this.getClass().getName() + " createSetup ...");
type = new Type();
include.setViewId("pop/typeCreate.xhtml");
}

public void create(ActionEvent e) {
System.out.println(this.getClass().getName() + " create ...");
TypeRemote typeRemote = serviceLocator.getTypeRemote();
typeRemote.persist(type);
init();
}

public void delete(ActionEvent e) {
System.out.println(this.getClass().getName() + " delete ...");
TypeRemote typeRemote = serviceLocator.getTypeRemote();
typeRemote.remove(type.getId());
init();
}

public void del(ActionEvent e) {
System.out.println(this.getClass().getName() + " del ...");
String[] str = selectedItem.split("&");
for (int i = 0; i < str.length; i++) {
Long id = Long.valueOf(str[i]);
TypeRemote typeRemote = serviceLocator.getTypeRemote();
typeRemote.remove(id);
}
// TypeRemote typeRemote = serviceLocator.getTypeRemote();
// typeRemote.remove(type.getId());
init();
}

public List getTypes() {
return types;
}

public Type getType() {
if (type == null) {
type = new Type();
}
return type;
}

public void setType(Type type) {
this.type = type;
}

public String getSelectedItem() {
return selectedItem;
}

public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
}

//*************************** Server ******************//

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.oak.jsfcn.server.session.admin.impl;

import org.oak.jsfcn.server.session.admin.*;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.oak.jsfcn.server.entity.Type;
import org.oak.util.GenKeyUtil;

/**
*
* @author KennyLin
*/
@Stateless
public class TypeBean implements TypeRemote {

@PersistenceContext
private EntityManager em;

public void persist(Type type) {
type.setId(GenKeyUtil.getId(em, "cn_type"));
em.persist(type);
}

public void merge(Type type) {
em.merge(type);
}

public void remove(Long id) {
Type type = em.find(Type.class, id);
em.remove(type);
}

public Type find(Long id) {
return em.find(Type.class, id);
}

public List find(String propertyName, Object val) {
List types = em.createQuery("SELECT c FROM Type c WHERE c." + propertyName + " = :propertyName").setParameter("propertyName", val).getResultList();
return types;
}

public List findAll() {
List types = em.createQuery("SELECT c FROM Type c").getResultList();
return types;
}
}

//********************************

[img]http://hiphotos.baidu.com/kennylin2008/pic/item/e4dd79136e8498936438dbbf.jpg[/img]
[img]http://hiphotos.baidu.com/kennylin2008/pic/item/87c559de8317834bcdbf1a11.jpg[/img]
[img]http://hiphotos.baidu.com/kennylin2008/pic/item/82cbdffabd58299a9f514611.jpg[/img]
[img]http://hiphotos.baidu.com/kennylin2008/pic/item/7ef4f5307aaaea8aa8018e0b.jpg[/img]