[jboss-user] [JBoss Seam] - Re: the method invoked twice, when render the page once!

chlol do-not-reply at jboss.com
Thu Oct 18 23:21:29 EDT 2007


i use the @Factory,but can't solve the question

my list bean generated jboss gen:
package cn.sh.guanghua.manhour.service.admin;
  | 
  | import org.jboss.seam.Component;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Factory;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.framework.EntityQuery;
  | 
  | import java.util.ArrayList;
  | import java.util.List;
  | import java.util.Arrays;
  | 
  | import javax.faces.model.SelectItem;
  | import javax.persistence.Query;
  | 
  | import cn.sh.guanghua.manhour.common.Constants;
  | import cn.sh.guanghua.manhour.model.admin.User;
  | import cn.sh.guanghua.manhour.service.Authenticator;
  | 
  | @Name("userList")
  | public class UserList extends EntityQuery {
  | 
  | 	
  | 	private long projectId = -1;
  | 
  | 	/**
  | 	 * 
  | 	 */
  | 	private static final long serialVersionUID = -4312632636363206451L;
  | 
  | 	private static final String[] RESTRICTIONS = {
  | 			"lower(user.username) like concat('%',concat(lower(#{userList.user.username}),'%'))",
  | 			"lower(user.name) like concat('%',concat(lower(#{userList.user.name}),'%'))"};
  | 
  | 	private User user = new User();
  | 
  | 	@Override
  | 	public String getEjbql() {
  | 			return "select user from User user where username <> 'admin'";
  | 	}
  | 
  | 	@Override
  | 	public Integer getMaxResults() {
  | 		return 15;
  | 	}
  | 
  | 	public User getUser() {
  | 		return user;
  | 	}
  | 
  | 	@Override
  | 	public List<String> getRestrictions() {
  | 		List<String> list = new ArrayList<String>();
  | 		
  | 		if (this.getUser().getState() == 0) {
  | 			list.add("lower(user.state) = #{userList.user.state}");
  | 		}
  | 		else if (this.getUser().getState() == 1) {
  | 			list.add("lower(user.state) = #{userList.user.state}");
  | 		}
  | 		else {
  | 			//do nothing
  | 		}
  | 		list.addAll(Arrays.asList(RESTRICTIONS));
  | 		return list;
  | 	}
  | 	
  | 	/**
  | 	 * @return
  | 	 */
  | 	@SuppressWarnings("unchecked")
  | 	@Factory(scope=ScopeType.CONVERSATION)
  | 	public List<SelectItem> getUsersByManager() {
  | 		Authenticator authenticator = (Authenticator) Component.getInstance("authenticator");
  | 		User loginUser = authenticator.getUser();
  | 		List<SelectItem> list = new ArrayList<SelectItem>();
  | 		list.add(new SelectItem(loginUser.getId(), loginUser.getName()));
  | 		
  | 		Query query = getEntityManager().createQuery("select user from User user " +
  | 				"where user.username <> 'admin' and user.state = 0 " +
  | 				" and user.userManager.id=" + loginUser.getId() + " and user.id <> " + loginUser.getId());
  | 		List<User> users = query.getResultList();
  | 		for (User user : users) {
  | 			list.add(new SelectItem(user.getId(), user.getName()));
  | 		}	
  | 		return list;
  | 	}
  | 	
  | 	
  | 	
  | }
  | 

my page code invoking the method:
<h:selectOneMenu id="principalId" value="#{activityList.principalId}" onchange="javascript:document.getElementById('weekActivity').submit();">
  |                 	<f:selectItems value="#{userList.usersByManager}"/>
  |                 </h:selectOneMenu

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

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



More information about the jboss-user mailing list