JSF PrimeFaces ile ekranda görüntülenen liste kayıt sayısını arttırma,yenileme kodu kullanımı örneği (JSF PrimeFaces increment, refresh list record number on page code usage example)

JSF sayfanızda bir listeyi ekrana yansıtmak veya daha önceden ekrana bastığınız listeyi güncellemek için p:commandLink veya p:commandButton u aşağıdaki gibi kullanabilirsiniz. Burada ViewScoped kullanarak bir önceki listenin kaçında kayıtta kaldığını elde tutabilmiş oluyoruz.

package net.yazilimcity.jsf.refreshlist.ui;

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

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import net.yazilimcity.jsf.lov.ActiveStatus;
import net.yazilimcity.jsf.model.Announcement;
import net.yazilimcity.jsf.service.AnnouncementServiceI;
import net.yazilimcity.jsf.service.core.ServiceFactory;
import net.yazilimcity.jsf.util.BeanUtil;

/**
 * This is the Bean class for operations in the refreshList.xhtml.
 * 	operations -> fetchList 
 * 
 * 
 * @author oguzhankinik
 */

@ManagedBean(name = "myBean")
@ViewScoped
public class MyBean {
	
	private int lastListLimit;
	private List<User> listUser;
	private static ServiceFactory serviceFactory = ServiceFactory.getInstance();
	private UserServiceI userService;
	
	// cons
	public AnnouncementBean() {
		lastListLimit = 2;
		listUser = new ArrayList<User>();
		listUser = userService.getUsers(2);
	}
	
	public void moreUser() {
		lastListLimit += 2;
		listUser = userService.getUsers(lastListLimit);
	}

	// methods
	public int getLastListLimit() {
		return lastListLimit;
	}

	public void setLastListLimit(int lastListLimit) {
		this.lastListLimit = lastListLimit;
	}

	public List<User> getListUser() {
		return listUser;
	}

	public void setListUser(List<User> listUser) {
		this.listUser = listUser;
	}
	
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<f:facet name="first">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
		<title>My User Page</title>
	</f:facet>
</h:head>

<h:body>
	<h:form id="userForm">
				
		<ui:repeat var="user" value="#{myBean.listUser}">
			<div>
			        <h:outputText value="#{user.name}" />
			</div>
		</ui:repeat>
		
		<p:commandButton id="nextBtn" action="#{myBean.moreUser()}" update=":userForm"></p:commandButton>
		
		<p:commandLink update=":userForm" actionListener="#{myBean.moreUser()}">  
			<h:outputText value="Devamı..."/>  
		</p:commandLink>  
   		
	</h:form>
</h:body>
</html>
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on StumbleUpon0Share on Reddit0

Leave a Reply


*