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

以下是本人做的demo

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

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

<?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: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">
<body>
<ui:composition template="/template/template.xhtml">

<ui:param name="path" value="#{facesContext.externalContext.requestContextPath}"/>
<ui:define name="title">Type</ui:define>
<ui:define name="body">


<script type="text/javascript">

// <![CDATA[

// ]]>
</script>

<a4j:form id="fm1" name="fmn1">
<h:panelGrid columns="2" style="width:100%;">
<rich:panel header="" id="left" style="width:200;height:440;">
<h:panelGrid columns="1">
<h:outputText id="txtId" value="#{typePage.type.id}"/>
<h:outputText id="txtName" value="#{typePage.type.name}"/>
<!-- <a4j:commandLink oncomplete="Richfaces.showModalPanel('mp');" reRender="pnl2" actionListener="#{typePage.detailSetup}" value="commit"/>-->
</h:panelGrid>
</rich:panel>
<rich:panel header="right title" style="width:540;height:440;" id="right">
<h:outputText id="optChoose" value=""/>
<h:inputHidden id="hid2" value="#{typePage.selectedItem}"/>
<input type="checkbox" value="" id="chk2" title="java" οnclick="checkAll('chk2','mycheckbox')" />
<a4j:commandLink value="btNtest" reRender="chk" οnclick="linkAll('chk2','mycheckbox');"/>
<h:outputText id="txtId2" value="#{typePage.type.name}"/>
<rich:dataTable id="types" rowKeyVar="rkv" onRowClick="rowClick(this)" sortMode="single" columnsWidth="30" binding="#{typePage.dataTable}" onRowMouseOver="rowOver(this)" footerClass="dr-table-header rich-table-header " onRowMouseOut="rowOut(this)" style="width:95%;" value="#{typePage.types}" var="item">
<a4j:support event="onRowDblClick" reRender="pnl2" oncomplete="Richfaces.showModalPanel('mp');" actionListener="#{typePage.editSetup}"/>
<f:facet name="header">
<h:outputText value="I love java"/>
</f:facet>
<rich:column id="read">
<f:facet name="header">
<h:outputText styleClass="headerText"
value="read" />
</f:facet>
<span οnclick="alert('aaa')">
<input type="checkbox" id="chkId_#{rkv}" οnclick="ck2(this)" name="mycheckbox" value="#{item.id}"/>
</span>
</rich:column>

<rich:column sortable="true" sortBy="#{item.id}" selfSorted="true" headerClass="dr-table-header rich-table-header ">
<f:facet name="header">
<h:outputText value="id"/>
</f:facet>
<h:outputText id="tblId" value="#{item.id}"/>
</rich:column>
<rich:column sortBy="#{item.name}" headerClass="dr-table-header rich-table-header " id="colName">
<f:facet name="header">
<h:outputText id="tblName" value="name"/>
</f:facet>
<h:outputText value="#{item.name}"/>
</rich:column>
<rich:column sortBy="#{item.describ}">
<f:facet name="header">
<h:outputText value="describ"/>
</f:facet>
<h:outputText value="#{item.describ}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="audit"/>
</f:facet>
<h:outputText id="tblAudit" value="#{item.audit}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="btn"/>
</f:facet>
<a4j:commandButton value="ee"/>
</rich:column>

<f:facet name="footer">

</f:facet>
</rich:dataTable>

<a4j:commandButton value="添加" id="btnAdd" reRender="pnl2" oncomplete="Richfaces.showModalPanel('mp');" actionListener="#{typePage.createSetup}"/>
<a4j:commandButton value="删除" reRender="optChoose,types" οnclick="c('fm1','mycheckbox')" actionListener="#{typePage.del}"/>
</rich:panel>

</h:panelGrid>


</a4j:form>

<table>
<c:forEach items="#{typePage.types}" var="item">
<tr><td οnclick="A4J.AJAX.Submit('_viewRoot','fm1',event,{'oncomplete':alert('javaee'),'parameters':{'fm1:btnAdd':'fm1:btnAdd'} ,'actionUrl':'/jsf1.2-demo/jsfcn/type.jsf'} )">#{item.name}</td></tr>
</c:forEach>
</table>
<!-- ******************* pop panel -->
<rich:modalPanel id="mp" moveable="true" width="580" height="400" resizeable="false">
<f:facet name="header">
<h:outputText value="Type Title" />
</f:facet>
<f:facet name="controls">
<a href="javascript:Richfaces.hideModalPanel('mp')">close</a>
</f:facet>
<a4j:outputPanel id="pnl2">
<a4j:include id="icd" binding="#{typePage.include}" viewId="pop/tmp.xhtml"/>
</a4j:outputPanel>
</rich:modalPanel>
</ui:define>
</ui:composition>
</body>
</html>

/************************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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值