0

Dynamic MenuBar with dynamic popup items

asked 2009-12-07 12:43:38 +0800

dhamu gravatar image dhamu
165 1 6

I want to create a menubar with sub menus and sub-sub menus for my application. However, the actual list of items appearing in my menus must be dynamic. I have the logic to retrieve the menu configuration at run-time from the database. However, I need to figure out an elegant way to populate the menubar with the various labels, and menuitems.

Obviously, this cannot be done with vanilla ZK. Any suggestions? Does it make sense to use the ZK API and write the logic in Java or is there a way to manipulate the content of a menubar and the various labels, menupopups and menuitems through scripting?

Your assistance is greatly appreciated.

Dave

delete flag offensive retag edit

25 Replies

Sort by ยป oldest newest

answered 2010-09-13 06:32:04 +0800

yaiyaikung gravatar image yaiyaikung
30

public abstract class MainMenuControlsModelBase {
	@Resource
	protected MainMenuControlsDAO beanDAO;
	
	protected MainMenuControls selected;
	protected String queryString;
	protected String where;
	protected String orderBy;
	protected int offset;
	protected int maxResults;
	protected Map<String, ?> parameters;

	public MainMenuControlsDAO getDAO() {
		return beanDAO;
	}
	
	public void setDAO(MainMenuControlsDAO beanDAO) {
		this.beanDAO = beanDAO;
	}
	
	public MainMenuControls getSelected() {
		return this.selected;
	}
	
	public void setSelected(MainMenuControls bean) {
		this.selected = bean;
	}
	
	public void setWhere(String where) {
		this.where = where;
	}
	
	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	
	public void setOffset(int offset) {
		this.offset = offset;
	}
	
	public int getOffset() {
		return this.offset;
	}
	
	public void setMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}
	
	public int getMaxResults() {
		return this.maxResults;
	}
	
	public String getQueryString() {
		if (queryString != null) {
			return this.queryString;
		}
		return generateQueryString(this.where, this.orderBy);
	}
	
	public void setQueryString(String queryString) {
		this.queryString = queryString;
	}
	
	public Map<String,?> getParameters() {
		return this.parameters;
	}
	
	public void setParameters(Map<String,?> params) {
		this.parameters = params;
	}
	
	//-- DB access on the selected bean --//
	public void persist() {
		beanDAO.persist(selected);
	}
	
	public void merge() throws EntityNotFoundException {
		beanDAO.merge(selected);
	}
	
	public void delete() throws EntityNotFoundException {
		beanDAO.delete(selected);
	}
	
	private List<MainMenuControls> listAll;
	public void dataTree(){
		
		setWhere("");
		setParameters(null);
		setOrderBy("PARENT_MENU_ID,SEQ_MENU_LEVEL");
		setMaxResults(getTotalSize());
		listAll = getAll();
		
		treeMapDB = new TreeMap();
		for (Iterator<MainMenuControls> it = listAll.iterator(); it.hasNext();) {
			MainMenuControls childTask = it.next();
			//System.out.println(childTask.toString());	
			treeMapDB.put(childTask.getMain_menu_id(),childTask);
		}
		
	}
	
	private SortedMap <Integer,MainMenuControls> treeMapDB;
	public SortedMap<Integer, MainMenuControls> getTreeMapDB() {
		return treeMapDB;
	}
	public void setTreeMapDB(SortedMap<Integer, MainMenuControls> treeMapDB) {
		this.treeMapDB = treeMapDB;
	}
	
	public List<MainMenuControls> getAll() {
		return beanDAO.find(getQueryString(), this.offset, this.maxResults, getParameters());
	}
	
	public MainMenuControls get() {
		return (MainMenuControls)beanDAO.findSingle(getQueryString() , getParameters());
		//return beanDAO.find(getQueryString(), this.offset, this.maxResults, getParameters());
	}
	
	public List<MainMenuControls> findByParentId(Integer parentId){
		
		List<MainMenuControls> childList = new ArrayList<MainMenuControls>();
		Iterator<MainMenuControls> it = listAll.iterator();
		
		while (it.hasNext()) {
			MainMenuControls childTask = it.next();	
			//System.out.println(" list parent : "+childTask.parent_menu_id + "|"+parentId);
			if(childTask.parent_menu_id!=null){
				if(childTask.parent_menu_id.equals(parentId)){
					//System.out.println(" list parent : "+childTask.parent_menu_id + "|"+parentId);
					childList.add(childTask);
				//	listAll.remove(childTask);
				}
			}else{
				//listAll.remove(childTask);
			}
				
		}
		
		return childList;
	}
	
	
	//paging total size
	public int getTotalSize() {
		final String queryString = 
			"SELECT COUNT(*) " 
			+ getQueryString();
		final Object res = beanDAO.findSingle(queryString, getParameters());
		final int sz = (res instanceof Number) ? ((Number)res).intValue() : 0;
		return sz < 0 ? Integer.MAX_VALUE : sz;
	}
	
	//-- overridable --//
	/** Generate query string */ 
	protected String generateQueryString(String where, String orderBy) {
		final StringBuffer sb = new StringBuffer(256);
		sb.append("FROM "+MainMenuControls.class.getName());
		if (!Strings.isBlank(where)) {
			sb.append(" WHERE "+where);
		}
		if (!Strings.isBlank(orderBy)) {
			sb.append(" ORDER BY "+orderBy);
		}
		return sb.toString();
	
} and my EntityDAO class

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import treehibernate.mainMenuControls.base.MainMenuControls;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.spring.jpa.BasicDAO;
import org.zkoss.spring.jpa.EntityNotFoundException;

@Scope("idspace")
@Repository
public class MainMenuControlsDAO {
	
	@Resource
	protected BasicDAO basicDAO;

	public BasicDAO getBasicDao() {
		return basicDAO;
	}

	public void setBasicDao(BasicDAO basicDao) {
		this.basicDAO = basicDao;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(readOnly=true)
	public List<MainMenuControls> find(String queryString, int offset, int maxResults, Map<String,?> params) {
		List<?> all = this.basicDAO.find(queryString, offset, maxResults, params);
		return (List<MainMenuControls>) all;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(readOnly=true)
	public Object findSingle(String queryString, Map<String,?> params) {
		return this.basicDAO.findSingle(queryString, params);
	}
	
	@Transactional(readOnly=false,propagation = Propagation.REQUIRED)
	public void persist(MainMenuControls bean){
		this.basicDAO.persist(bean);
	}
	
	@Transactional(readOnly=false,propagation = Propagation.REQUIRED)
	public void delete(MainMenuControls bean) throws EntityNotFoundException {
		Serializable pk = bean.getMain_menu_id();

		this.basicDAO.remove(MainMenuControls.class, pk);
	}

	@Transactional(readOnly=false,propagation = Propagation.REQUIRED)
	public void merge(MainMenuControls bean) throws EntityNotFoundException {
		this.basicDAO.merge(bean);
	}
}
where i must implement getRoot() and getDefault() and my zk is
<div>
	<dbmenu id="mainMenu" autodrop="true" model="@{??????????????? }" 
			onClick="label1.value=??????????????????????;" />
	<label id="label1" />
</div>
zul(View) call MainMenuControlsModel class ex.
<row>Menu Display :<label value="@{mainMenuControlsModel.selected.main_menu_display}"/></row>
<row>Relate Rrocess Cd :<label value="@{mainMenuControlsModel.selected.relate_process_cd}"/></row>
<row>Parent Menu :<label value="@{mainMenuControlsModel.selected.parent_menu_id}"/></row>
@Scope("idspace")
@Component
public class MainMenuControlsModel extends MainMenuControlsModelBase {
	
}
link publish delete flag offensive edit

answered 2010-09-13 06:23:29 +0800

yaiyaikung gravatar image yaiyaikung
30

Thank you Bence,

Yes, I did it! I removed it but error so must override method of TreeNode interface and
I can't remove a @Column(name = "SEQ_MENU_LEVEL") .....
because i will be use it to CRUD.
I know what's problem of your suggestion is it not work for my mapping such as

@IndexColumn(name="SEQ_MENU_LEVEL", base = AppInfo.BASE)
AppInfo.BASE where is it library or package of AppInfo.BASE
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER) 

and if i use @ManyToOne and @OneToMany together compile create basicBean is error!

and please example implementation getRoot() and getDefault()
if It's my DAO and EntityModel classes

I hope you understand me,

link publish delete flag offensive edit

answered 2010-09-13 04:34:29 +0800

btakacs gravatar image btakacs
153 3 4

Hi, yaiyaikung

Did you even read my previous post?
Please do what I suggested. You should concentrate the word: "remove".

Other thing: If your getDefault method returns null, then what will you display by default? Nothing. Is this the behaviour you intend to impement?

Third thing: read my older posts: I suggested to implement "getRoot(), and getDefault() for your dao", but you put them into the entity...

I know JPA is a little bit complex at the first glance, and may cause confusion if you want too big thing first time. I suggest you start studying the JPA specification. And start a pilot project with more simple examples to get to know that. Write some CRUD tests, modify the mapping, and check behaviour of the framework with that. Spring JPA has many useful classes to help Unit testing.

Regards:
Bence

link publish delete flag offensive edit

answered 2010-09-13 02:35:42 +0800

yaiyaikung gravatar image yaiyaikung
30

Hi, Bence

It's error, How i can do it?
I use spring zk


INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@502819: defining beans
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'basicDAO': Injection of persistence methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/datasource-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: zkspringjpa] Unable to build EntityManagerFactory
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [config/datasource-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [config/datasource-context.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/datasource-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: zkspringjpa] Unable to build EntityManagerFactory
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [config/datasource-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [config/datasource-context.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/datasource-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: zkspringjpa] Unable to build EntityManagerFactory
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:324)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:996)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/datasource-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: zkspringjpa] Unable to build EntityManagerFactory
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [config/datasource-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [config/datasource-context.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/datasource-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: zkspringjpa] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:308)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:297)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:224)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:503)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:473)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:598)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:569)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:192)
at org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:117)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:321)
... 31 more

link publish delete flag offensive edit

answered 2010-09-13 02:35:28 +0800

yaiyaikung gravatar image yaiyaikung
30

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.IndexColumn;

import th.co.truecorp.ess.nips.master.util.menu.TreeNode;

@Entity(name="MainMenuControls")
@Table( name ="MAIN_MENU_CONTROLS")
public class MainMenuControls implements TreeNode
{
//private static final long serialVersionUID = 1L;

public TreeNode getChildAt(int childIndex) {

return null;
}
public int getChildCount() {
return children.size();
}


public Long getId() {
return this.main_menu_id.longValue();
}


public String getName() {
return this.main_menu_display;
}


public boolean isLeaf() {
if(children.size()==0)
return true;
else
return false;
}

public boolean isRoot() {
if(parent_menu_id == 0 ||parent_menu_id==null)
return true;
else
return false;
}

public MainMenuControls getDefault(){

return null;
}

//Generate Class Body.
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof MainMenuControls)) return false;
MainMenuControls other = (MainMenuControls) obj;
if (this.getMain_menu_id() == null) {
if (other.getMain_menu_id() != null)return false;
} else if (! this.getMain_menu_id().equals(other.getMain_menu_id()))return false;
return true;
}

public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.getMain_menu_id() == null) ? 0 : this.getMain_menu_id().hashCode());
return result;
}
public MainMenuControls(){}

public MainMenuControls(MainMenuControls obj){
this.main_menu_id = obj.main_menu_id;
this.main_menu_display = obj.main_menu_display;
this.relate_process_cd = obj.relate_process_cd;
this.parent_menu_id = obj.parent_menu_id;
this.last_modified_date = obj.last_modified_date;
this.last_modified_user = obj.last_modified_user;
this.seq_menu_level = obj.seq_menu_level;
}

@Column(name = "MAIN_MENU_ID", nullable=false)
@SequenceGenerator(name="SQ_MAIN_MENU_ID", sequenceName="SQ_MAIN_MENU_ID")
@Id @GeneratedValue(generator="SQ_MAIN_MENU_ID")
protected Integer main_menu_id;
public void setMain_menu_id(Integer value) {
this.main_menu_id = value;
}
public Integer getMain_menu_id(){
return this.main_menu_id;
}

@Column(name = "MAIN_MENU_DISPLAY", nullable=false)
protected String main_menu_display;
public void setMain_menu_display(String value) {
this.main_menu_display = value;
}
public String getMain_menu_display(){
return this.main_menu_display;
}

@Column(name = "RELATE_PROCESS_CD")
protected String relate_process_cd;
public void setRelate_process_cd(String value) {
this.relate_process_cd = value;
}
public String getRelate_process_cd(){
return this.relate_process_cd;
}

@Column(name = "PARENT_MENU_ID")
protected Integer parent_menu_id;
public void setParent_menu_id(Integer value) {
this.parent_menu_id = value;
}
public Integer getParent_menu_id(){
return this.parent_menu_id;
}

@Column(name = "LAST_MODIFIED_USER", nullable=false)
protected String last_modified_user;
public void setLast_modified_user(String value) {
this.last_modified_user = value;
}
public String getLast_modified_user(){
return this.last_modified_user;
}

@Column(name = "LAST_MODIFIED_DATE", nullable=false)
protected java.util.Date last_modified_date;
public void setLast_modified_date(java.util.Date value) {
this.last_modified_date = value;
}
public java.util.Date getLast_modified_date(){
return this.last_modified_date;
}

@Column(name = "SEQ_MENU_LEVEL")
protected Long seq_menu_level;
public void setSeq_menu_level(Long value) {
this.seq_menu_level = value;
}
public Long getSeq_menu_level(){
return this.seq_menu_level;
}

@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "PARENT_MENU_ID", referencedColumnName = "MAIN_MENU_ID", insertable = false , updatable = false)
private MainMenuControls parent;
public MainMenuControls getParent() {
return parent;
}
public void setParent(MainMenuControls parent) {
this.parent = parent;
}

@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@IndexColumn(name = "SEQ_MENU_LEVEL")
@JoinColumn(name="PARENT_MENU_ID", nullable=false)
private List<MainMenuControls> children;
public List<MainMenuControls> getChildren() {
return children;
}
public void setChildren(List<MainMenuControls> children) {
this.children = children;
}
}

link publish delete flag offensive edit

answered 2010-09-08 06:59:33 +0800

btakacs gravatar image btakacs
153 3 4

Hi, yaiyaikung

First: not override, but implementation the interface.

Second: if you use SEQ_MENU_LEVEL as an IndexColumn, you should not have explicit getters and setters for that.

So remove

@Column(name = "SEQ_MENU_LEVEL")
protected Long seq_menu_level;
public void setSeq_menu_level(Long value) {
this.seq_menu_level = value;
}
public Long getSeq_menu_level(){
return this.seq_menu_level;
}

modify your constructor accordingly
and remove the "@Override" before the method implementations of the interface.

Before you start to implement such an application, you should study JPA more deeply.
And some ZK study would be useful too...

link publish delete flag offensive edit

answered 2010-09-08 05:05:35 +0800

yaiyaikung gravatar image yaiyaikung
30

Bence ,Help me Please

------------------------------------------------------------------------------------------------------
error here!
.......
.......
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
@IndexColumn(name="SEQ_MENU_LEVEL", base = AppInfo.BASE)
@JoinColumn(name="PARENT_MENU_ID", nullable=false)

.......
.......


......
and I Override methods of TreeNode right?
if i delete @IndexColumn(name="SEQ_MENU_LEVEL", base = AppInfo.BASE)
then can compile but runtime error


@Override
public TreeNode getChildAt(int childIndex) {

return null;
}

@Override
public int getChildCount() {
return 0;
}

@Override
public Long getId() {
return this.main_menu_id.longValue();
}

@Override
public String getName() {
return this.main_menu_display;
}

@Override
public boolean isLeaf() {

return false;
}

@Override
public boolean isRoot() {
if(parent_menu_id == 0 ||parent_menu_id==null)
return true;
else
return false;
}

public MainMenuControls getRoot(){
if(parent_menu_id == 0 ||parent_menu_id==null)
return this.main_menu_id;
}

public MainMenuControls getDefault(){

return null;
}

........................................

link publish delete flag offensive edit

answered 2010-09-07 22:23:09 +0800

yaiyaikung gravatar image yaiyaikung
30

Hi Bence, Thank you for your help.
What if I have questions about ZK I will ask you again. And for your help,
if you come to Thailand. I will be your guide or suggest to attractions for you free! -:)

Yai,
King Mongkut's University of Technology Thonburi, Bangkok ,Thailand
[email protected]

link publish delete flag offensive edit

answered 2010-09-07 08:28:38 +0800

btakacs gravatar image btakacs
153 3 4

Hi, yaiyaikung

Menuitem is the name of my entity. So for you you should modify your code:

@Entity(name="MainMenuControls")
@Table( name ="MAIN_MENU_CONTROLS")
public class MainMenuControls implements TreeNode

...and:
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER) 
@Cascade( { org.hibernate.annotations.CascadeType.ALL} )
@IndexColumn(name = "position", base = AppInfo.BASE)
@JoinColumn(name="PARENT_MENU_ID", nullable=false)
private List<MainMenuControls> children;
public List<MainMenuControls> getChildren() {
	return children;
}

public void setChildren(List<MainMenuControls> children) {
	this.children = children;
}

@ManyToOne()
@JoinColumn(name="PARENT_MENU_ID", insertable=false, updatable=false, nullable=false)
private MainMenuControlsparent; 
public MainMenuControlsgetParent() {
	return parent;
}

I guess, maybe my position is your SEQ_MENU_LEVEL, is it?

Hey, this way I'm writing the your ORM code... If you continue asking not ZK related questions, I will send you the bill ;-)

link publish delete flag offensive edit

answered 2010-09-07 05:24:27 +0800

yaiyaikung gravatar image yaiyaikung
30

updated 2010-09-07 05:29:53 +0800

thank you Bence,
this is my full Mapping class :

-----------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.zkoss.zul.Menuitem;


@Entity(name="MainMenuControls")
@Table( name ="MAIN_MENU_CONTROLS")
public class MainMenuControls
{
//Generate Class Body.
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof MainMenuControls)) return false;
MainMenuControls other = (MainMenuControls) obj;
if (this.getMain_menu_id() == null) {
if (other.getMain_menu_id() != null)return false;
} else if (! this.getMain_menu_id().equals(other.getMain_menu_id()))return false;
return true;
}

public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.getMain_menu_id() == null) ? 0 : this.getMain_menu_id().hashCode());
return result;
}
public MainMenuControls(){}

public MainMenuControls(MainMenuControls obj){
this.main_menu_id = obj.main_menu_id;
this.main_menu_display = obj.main_menu_display;
this.relate_process_cd = obj.relate_process_cd;
this.parent_menu_id = obj.parent_menu_id;
this.last_modified_date = obj.last_modified_date;
this.last_modified_user = obj.last_modified_user;
this.seq_menu_level = obj.seq_menu_level;
}

@Column(name = "MAIN_MENU_ID", nullable=false)
@SequenceGenerator(name="SQ_MAIN_MENU_ID", sequenceName="SQ_MAIN_MENU_ID")
@Id @GeneratedValue(generator="SQ_MAIN_MENU_ID")
protected Integer main_menu_id;
public void setMain_menu_id(Integer value) {
this.main_menu_id = value;
}
public Integer getMain_menu_id(){
return this.main_menu_id;
}

@Column(name = "MAIN_MENU_DISPLAY", nullable=false)
protected String main_menu_display;
public void setMain_menu_display(String value) {
this.main_menu_display = value;
}
public String getMain_menu_display(){
return this.main_menu_display;
}

@Column(name = "RELATE_PROCESS_CD")
protected String relate_process_cd;
public void setRelate_process_cd(String value) {
this.relate_process_cd = value;
}
public String getRelate_process_cd(){
return this.relate_process_cd;
}

@Column(name = "PARENT_MENU_ID")
protected Integer parent_menu_id;
public void setParent_menu_id(Integer value) {
this.parent_menu_id = value;
}
public Integer getParent_menu_id(){
return this.parent_menu_id;
}

@Column(name = "LAST_MODIFIED_USER", nullable=false)
protected String last_modified_user;
public void setLast_modified_user(String value) {
this.last_modified_user = value;
}
public String getLast_modified_user(){
return this.last_modified_user;
}

@Column(name = "LAST_MODIFIED_DATE", nullable=false)
protected java.util.Date last_modified_date;
public void setLast_modified_date(java.util.Date value) {
this.last_modified_date = value;
}
public java.util.Date getLast_modified_date(){
return this.last_modified_date;
}

@Column(name = "SEQ_MENU_LEVEL")
protected Long seq_menu_level;
public void setSeq_menu_level(Long value) {
this.seq_menu_level = value;
}
public Long getSeq_menu_level(){
return this.seq_menu_level;
}


@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="parent", nullable=false)
private List<Menuitem> children;
public List<Menuitem> getChildren() {
return children;
}

public void setChildren(List<Menuitem> children) {
this.children = children;
}

@ManyToOne()
@JoinColumn(name="parent", insertable=false, updatable=false, nullable=false)
private Menuitem parent;
public Menuitem getParent() {
return parent;
}
}

//////////////////////////////////////////////////////////////////////////////

Can i edit you code in MenuItem --- > Menuitem ?
and What is the package of the MenuItem?

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: 2009-12-07 12:43:38 +0800

Seen: 4,143 times

Last updated: Sep 29 '10

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