[jboss-user] [JBoss Seam] - Re: Interceptor for seam component

chlol do-not-reply at jboss.com
Fri Aug 17 05:45:04 EDT 2007


i do it as the doc,but i can't invoke the interceptor,my code is the following

theinterceptor:
package cn.sh.guanghua.manhour.service.manhour;

import java.lang.reflect.Modifier;
import java.util.Map;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.log.Log;

import cn.sh.guanghua.manhour.model.manhour.Logs;

@Name("logsHome")
public class LogsHome extends EntityHome {
	@Logger
	Log log;
	
	public void setLogsId(Long id) {
		setId(id);
	}

	public Long getLogsId() {
		return (Long) getId();
	}

	@Override
	protected Logs createInstance() {
		Logs logs = new Logs();
		return logs;
	}

	public void wire() {
	}

	public boolean isWired() {
		return true;
	}

	public Logs getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}
	
	@AroundInvoke
	public Object doLogs(InvocationContext inv) throws Exception {
		int methodModify = inv.getMethod().getModifiers();
		String methodName = inv.getMethod().getName();
		System.out.println("1111111111111111111111111111111111111111111");
		if (methodModify == Modifier.PUBLIC 
				&& (methodName.startsWith("create") 
						|| methodName.startsWith("update")
						|| methodName.startsWith("persist")
						|| methodName.startsWith("remove"))) {
			
			Map data = inv.getContextData();
			Object target = inv.getTarget();
			log.debug("ContextData:" + data);
			log.debug("Target:" + target);
		}
		
		return inv.proceed();
	}

}


the invoke interceptor class:
package cn.sh.guanghua.manhour.service.admin;

import java.util.ArrayList;
import java.util.List;

import javax.interceptor.Interceptors;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

import cn.sh.guanghua.manhour.model.admin.Role;
import cn.sh.guanghua.manhour.model.admin.RoleResource;
import cn.sh.guanghua.manhour.service.manhour.LogsHome;

@Name("roleHome")
@Interceptors(LogsHome.class)
public class RoleHome extends EntityHome {

	public void setRoleId(Long id) {
		setId(id);
	}

	public Long getRoleId() {
		return (Long) getId();
	}

	@Override
	protected Role createInstance() {
		Role role = new Role();
		return role;
	}

	public void wire() {
	}

	public boolean isWired() {
		return true;
	}

	public Role getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List getRoleResources() {
		return getInstance() == null ? null : new ArrayList(
				getInstance().getRoleResources());
	}

}

but when RoleHome excute the persist method,the interceptor don't work

thank you!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4075146#4075146

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4075146



More information about the jboss-user mailing list