0

ZK+spring+hibernate??分???

asked 2006-11-13 07:34:06 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4008625

By: nobody

page.java

package com.gefon.zul;

import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Button;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Label;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Toolbarbutton;
import org.zkoss.zul.Window;

public class Page extends Grid {
int totalPage = 0;

int currPage = 0;

int pageSize = 10;

int count = 0;

String id;

String[] fields;

List allData = new ArrayList();

List currData = new ArrayList();

public void init(List data,String[] fields){
Window paging_window = new Window();
id = String.valueOf((new Date()).getTime());
paging_window.setId(id);

Button first = new Button();
first.setId("first");
first.setLabel("?");
first.addEventListener("onClick", new EventListener(){
public boolean isAsap(){
return true;
}
public void onEvent(Event event){
firstPage();
}
});
first.setParent(paging_window);

Button previous = new Button();
previous.setId("previous");
previous.setLabel("W@?");
previous.addEventListener("onClick", new EventListener(){
public boolean isAsap(){
return true;
}
public void onEvent(Event event){
previousPage();
}
});
previous.setParent(paging_window);

Button next = new Button();
next.setId("next");
next.setLabel("U@?");
next.addEventListener("onClick", new EventListener(){
public boolean isAsap(){
return true;
}
public void onEvent(Event event){
nextPage();
}
});
next.setParent(paging_window);

Button last = new Button();
last.setId("last");
last.setLabel("?");
last.addEventListener("onClick", new EventListener(){
public boolean isAsap(){
return true;
}
public void onEvent(Event event){
lastPage();
}
});
last.setParent(paging_window);

Label showpage =new Label();
showpage.setId("showpage");
showpage.setParent(paging_window);

Textbox jump = new Textbox();
jump.setId("jump");
jump.setWidth("30px");
jump.setParent(paging_window);

Button jumpbutton = new Button();
jumpbutton.setId("jumpbutton");
jumpbutton.setLabel("?");
jumpbutton.addEventListener("onClick", new EventListener(){
public boolean isAsap(){
return true;
}
public void onEvent(Event event){
jumpPage();
}
});
jumpbutton.setParent(paging_window);

paging_window.setParent(this.getParent());

this.allData = data;
count = allData.size();
if (count % pageSize == 0)
totalPage = count / pageSize;
else
totalPage = count / pageSize + 1;

this.fields=fields;
firstPage();
}
public void pageInit() {
currPage = 0;
}

public void buttonEnable() {
((Button)this.getParent().getFellow(id).getFellow("first")).setDisabled(false)
;
((Button)this.getParent().getFellow(id).getFellow("previous")).setDisabled(fal
se);
((Button)this.getParent().getFellow(id).getFellow("last")).setDisabled(false);
((Button)this.getParent().getFellow(id).getFellow("next")).setDisabled(false);
if (currPage == 0) {
((Button)this.getParent().getFellow(id).getFellow("first")).setDisabled(true)
;
((Button)this.getParent().getFellow(id).getFellow("previous")).setDisabled(tr
ue);
}
if (currPage == totalPage - 1) {
((Button)this.getParent().getFellow(id).getFellow("last")).setDisabled(true);
((Button)this.getParent().getFellow(id).getFellow("next")).setDisabled(true);
}
}

public void showPage() {
((Label)this.getParent().getFellow(id).getFellow("showpage")).setValue((currPage
+ 1) + "/" + totalPage);
}

public void clear() {
currData = new ArrayList();
if (this.getRows() != null)
this.getRows().setParent(null);
}

public void iteratorList() {
buttonEnable();
Rows rows = new Rows();
Iterator it = currData.iterator();
while (it.hasNext()) {
Object obj = it.next();
try{
Map boMap = BeanUtils.describe(obj);
Row row = new Row();
for(int i=0;i<fields.length;i++){
Label label = new Label();
label.setValue(BeanUtils.getProperty(obj, fields[i]));
label.setParent(row);
row.setParent(rows);
}
}catch(Exception e){

}
}
rows.setParent(this);
showPage();
}

public void firstPage() {
pageInit();
clear();
Iterator it = allData.iterator();
for (int i = 0; i < count; i++) {
if (i >= currPage * pageSize && i < (currPage + 1) * pageSize) {
currData.add(it.next());
} else {
it.next();
}
}
iteratorList();
}

public void previousPage() {
clear();
currPage--;
Iterator it = allData.iterator();
for (int i = 0; i < count; i++) {
if (i >= currPage * pageSize && i < (currPage + 1) * pageSize) {
currData.add(it.next());
} else {
it.next();
}
}
iteratorList();
}

public void nextPage() {
clear();
currPage++;
Iterator it = allData.iterator();
for (int i = 0; i < count; i++) {
if (i >= currPage * pageSize && i < (currPage + 1) * pageSize) {
currData.add(it.next());
} else {
it.next();
}
}
iteratorList();
}

public void lastPage() {
clear();
Iterator it = allData.iterator();
currPage = totalPage - 1;
for (int i = 0; i < count; i++) {
if (i >= currPage * pageSize && i < (currPage + 1) * pageSize) {
currData.add(it.next());
} else {
it.next();
}
}
iteratorList();
}

public void jumpPage() {
clear();
currPage = Integer.parseInt(((Textbox)this.getParent().getFellow(id).getFellow
("jump")).getValue()) - 1;
Iterator it = allData.iterator();
for (int i = 0; i < count; i++) {
if (i >= currPage * pageSize && i < (currPage + 1) * pageSize) {
currData.add(it.next());
} else {
it.next();
}
}
iteratorList();
}
}

page.zul


<?xml version="1.0" encoding="gb2312"?>
<?page id="pagiation"?>
<?variable-resolver
class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window id="paging" title="" border="normal"
xmlns:h="http://www.w3.org/1999/xhtml">
<zscript>
List list = helpArticleDAO.loadArticle();
String[] fields={"title","publishshowname","replaycount","publishdate"};
</zscript>
<grid id="g_page" width="600px" use="com.gefon.zul.Page"
onCreate="g_page.init(list,fields)">
<columns>
<column label="D?" width="300px"/>
<column label="D??_H" width="80px"/>
<column label="^`" width="40px"/>
<column label="?" width="180px"/>
</columns>
</grid>


</window>


delete flag offensive retag edit

4 Replies

Sort by » oldest newest

answered 2006-11-14 07:55:20 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4011364

By: yiqianfeng

@?

link publish delete flag offensive edit

answered 2006-11-14 14:48:14 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4012105

By: nobody

how can i map spring virtual url so that zk engine can work on jsp?


link publish delete flag offensive edit

answered 2006-12-11 11:56:04 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4053332

By: matteo_barbieri

Hi,
I'm trying to start using ZK with Spring and Hibernate (until today I used Torque).
I've just started learning Hibernate and Spring, so sorry if this is a stupid question.
I see that there are in the zkplus packages some utility to use Hibernate and Spring easily, but I can't understand how to use them.
I understand that SpringUtil is used retrieve Spring beans easily, whithout the WebApplicationContextUtils.getRequiredWebApplicationContext(
(ServletContext)getDesktop().getWebApp().getNativeContext());

And I know that Hibernate is used to get a session and don't worry about the multi-threads problem.
But if I want to use both (Spring and Hibernate), what do I have to do?
For example in the Spring xml I had something like this:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

Now that I have to retrieve the sessionFactory from HibernateUtil, what class must I specify in the "sessionFactory" bean?

Thank you,
Bye

link publish delete flag offensive edit

answered 2006-12-14 03:28:34 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4059599

By: henrichen

When using ZK + Spring + Hibernate, just add this to WEB-INF/zk.xml to solve the multi-threads issue.

<listener>
<listener-class>org.zkoss.zkplus.spring.SpringTransactionSynchronizationListener
</listener-class>
</listener>

Then you do what Spring ask you to do. (Spring will control the Hibernate)

/henri


link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-11-13 07:34:06 +0800

Seen: 154 times

Last updated: Dec 14 '06

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More