package com.battleweb.beans;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.context.RequestContext;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

import com.battleejb.ejbbeans.URLBean;
import com.battleejb.entities.URL;

/**
 * 
 * @author Lukashchuk Ivan
 *
 */
@ManagedBean
@ViewScoped
public class LinksBean {

	@EJB
	private URLBean urlBean;
	
	private LazyDataModel<URL> dataModel;
	
	private URL url = new URL();	
	private URL newUrl = new URL();
	
	@PostConstruct
	private void init(){
		dataModel = new LazyDataModel<URL>() {
			
			private static final long serialVersionUID = 1L;
			
			@Override
			public List<URL> load(int first, int pageSize, String sortField,
					SortOrder sortOrder, Map<String, String> filters) {					
				setRowCount((int) urlBean.count());
				return urlBean.findRange(first, pageSize);						
			}
		};
	}
	
	public void create(){
		urlBean.create(newUrl);
		RequestContext.getCurrentInstance().closeDialog(null);
	}
	
	public void edit(){
		urlBean.edit(url);
	}
	
	public void closeDialog(){
		RequestContext.getCurrentInstance().closeDialog(null);
	}
	
	public LazyDataModel<URL> getDataModel() {
		return dataModel;
	}

	public void setDataModel(LazyDataModel<URL> dataModel) {
		this.dataModel = dataModel;
	}
	
	public void newUrl(){
		newUrl = new URL();
		Map<String, Object> options = new HashMap<String, Object>();
		options.put("modal", true);
		RequestContext.getCurrentInstance().openDialog(
				"adminCreateLink", options, null);		
	}

	public URL getUrl() {
		return url;
	}

	public void setUrl(URL url) {
		this.url = url;
	}

	public URL getNewUrl() {
		return newUrl;
	}

	public void setNewUrl(URL newUrl) {
		this.newUrl = newUrl;
	}

}

@@ -994,22 +994,33 @@
 ));%0A%09%09%09%09
-return
+List%3CURL%3E links =
  urlBean
@@ -1051,14 +1051,112 @@
 ze);
+%0A
 %09%09%09%09
-%09%09
+if (links != null && links.get(0).getId().equals(1))%7B%0A%09%09%09%09%09links.remove(0);%0A%09%09%09%09%7D%0A%09%09%09%09return links;
 %0A%09%09%09

Update LinksBean.java