DataTable not rendering properly

UI Components for JSF
Post Reply
scounthorpe
Posts: 4
Joined: 19 Nov 2010, 01:23

19 Nov 2010, 01:34

Hi,
I have a probleming rendering a Datatable with the following code.

To re-create the problem: Click search :- this outputs 12 records.
Next set share to 50. Then click search.

Now i have a Datable displaying 12 empty rows. Don't know how to solve this issue? Help!! :?

Code: Select all


<!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.prime.com.tr/ui">

 
<h:head>

</h:head>
  
<h:body>
	<h:form id="myForm">
		<ui:debug hotkey="i"/>
		
				
		<td width="950" style="vertical-align:top">  <!-- work area -->
								
						<table width="800" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td> 
								 	<h:inputText id="policyNumber" value="#{actRoleI.policyNumber}" size="14"/>  
         							<p:watermark for="policyNumber" value="Policy Number" />
								</td>
								<td>
									<h:inputText id="name" value="#{actRoleI.name}" size="14"/>  
         							<p:watermark for="name" value="Name" />
								</td>
								<td>
									<h:inputText id="number" value="#{actRoleI.number}" size="12"/>  
         							<p:watermark for="number" value="No" />
								</td>
								<td>
                					<h:selectOneMenu id="clientType" value="#{actRoleI.selectedType}">
									  <f:selectItems value="#{actRoleI.typeOptions}" />
									</h:selectOneMenu>
								</td>
								<td>
                					<h:selectOneMenu id="product" value="#{actRoleI.selectedProduct}">
									  <f:selectItems value="#{actRoleI.productOptions}" />
									</h:selectOneMenu>
								</td>
								<td>
								  	<p:commandButton value="Search" actionListener="#{actRoleI.search}" immediate="true" type="submit"  update="myForm:roleTable"
								  	onclick="PrimeFaces.cleanWatermarks()" oncomplete="PrimeFaces.showWatermarks()"/>
                				</td>
                													
							</tr>
						</table>
			
					
    				
    				<p:dataTable id="roleTable" var="role" value="#{actRoleI.roles}" 
							paginator="true" rows="10">    				

        				<f:facet name="header">
	            			Search Results
        				</f:facet>

        				<p:column>
	            			<f:facet name="header">
                				<h:outputText value="Policy" />
            				</f:facet>
            				<h:outputLink value="#{actRoleI.tempViewPolicy}">
								<h:outputText value="#{role.policyNo}"/>
							</h:outputLink>
        				</p:column>
        				<p:column filterBy="#{role.policyStatus}" filterOptions="#{actRoleI.policyStatusOptions}"  
			                 filterMatchMode="exact">
	            			<f:facet name="header">
                				<h:outputText value="Status" />
            				</f:facet>
            				<h:outputText value="#{role.policyStatus}"  />
        				</p:column>
        				
        				
        				         	
			        	<p:column>
	            			<f:facet name="header">
                				<h:outputText value="Product" />
            				</f:facet>
            				<h:outputText value="#{role.product}" />
        				</p:column>
        				<p:column>
	            			<f:facet name="header">
                				<h:outputText value="Role" />
            				</f:facet>
            				<h:outputText value="#{role.role}" />
        				</p:column>
        	
			        	<p:column>
	            			<f:facet name="header">
                				<h:outputText value="Type" />
            				</f:facet>
            				<h:outputText value="#{role.type}" />
        				</p:column>
        				<p:column filterBy="#{role.share}" filterOptions="#{actRoleI.shareOptions}">
	            			<f:facet name="header">
                				<h:outputText value="Share" />
            				</f:facet>
            				<h:outputText value="#{role.share}" />
        				</p:column>
        	
			        	<p:column>
	            			<f:facet name="header">
                				<h:outputText value="Name" />
            				</f:facet>
            				<h:outputLink value="#{actRoleI.tempViewName}">
								<h:outputText value="#{role.name}"/>
							</h:outputLink>            				
        				</p:column>
        				<p:column>
	            			<f:facet name="header">
                				<h:outputText value="No" />
            				</f:facet>
            				<h:outputText value="#{role.no}" />
        				</p:column>
	        	
    			    	<p:column>
				            <f:facet name="header">
                				<h:outputText value="Start Date" />
            				</f:facet>
            				<h:outputText value="#{role.startDate}" />
        				</p:column>
        				<p:column>
	            			<f:facet name="header">
                				<h:outputText value="Expiry Date" />
            				</f:facet>
            				<h:outputText value="#{role.expiryDate}" />
        				</p:column>
        	        	
        	        	
			       	</p:dataTable>
       	      </td>
       	      
	</h:form>
</h:body>
</html>

Code: Select all


package search;

import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;


@ManagedBean
@ViewScoped
public class ActRoleI implements Serializable {

	private SelectItem[] policyStatusOptions; 
	private SelectItem[] shareOptions;
	private SelectItem[] typeOptions;
	private SelectItem[] productOptions;
	private String selectedType;
	private String selectedProduct;
	
	
	private List<RoleS> roles;
	private String policyNumber;
	private String name;
	private String number;
	
	private final static String[] allPolicyStatusOptions;  
	private final static String[] allShareOptions;
	private final static String[] allTypeOptions;
	private final static String[] allProductOptions;
	
	
		
	
	static {  
		allPolicyStatusOptions = new String[2];  
		allPolicyStatusOptions[0] = "In-Force";  
		allPolicyStatusOptions[1] = "Complete";  
		
		allShareOptions = new String[2];
		allShareOptions[0] = "100";
		allShareOptions[1] = "50";
		
		allTypeOptions = new String[3];
		allTypeOptions[0] = "Client";
		allTypeOptions[1] = "Distributor";
		allTypeOptions[2] = "Agency";
		
		allProductOptions = new String[2];
		allProductOptions[0] = "Flexible";
		allProductOptions[1] = "Direct Pension";
    }  	
		
	public ActRoleI(){
				   		
		if(typeOptions==null){
			typeOptions = createFilterOptions(allTypeOptions, "Type");
		}
		if(productOptions==null){
			productOptions = createFilterOptions(allProductOptions, "Product");
		}		
	}


	public List<RoleS> getRoles() {
		policyStatusOptions = createFilterOptions(allPolicyStatusOptions, "Select");
		shareOptions = createFilterOptions(allShareOptions, "Select");		
		return roles;
	}	
	

	public void setRoles(List<RoleS> roles) {
		this.roles = roles;
	}


	public String getSelectedProduct() {
		return selectedProduct;
	}


	public void setSelectedProduct(String selectedProduct) {
		this.selectedProduct = selectedProduct;
	}


	public String getSelectedType() {
		return selectedType;
	}


	public void setSelectedType(String selectedTypes) {
		this.selectedType = selectedTypes;
	}

	
	
	private SelectItem[] createFilterOptions(String[] data, String displayString)  {  
		SelectItem[] options = new SelectItem[data.length + 1];  
		 
		options[0] = new SelectItem("", displayString);  
		for(int i = 0; i < data.length; i++) {  
			options[i + 1] = new SelectItem(data[i], data[i]);  
		}  
		  
		return options;  
	} 
	
	

	
	
	
	private List<RoleS> getTempRoles() {
		roles = new ArrayList<RoleS>(5);
		
		RoleS tempRoles2 = new RoleS();
		tempRoles2.setPolicyNo("22-0033-01");
		tempRoles2.setPolicyStatus("In-Force");
		tempRoles2.setProduct("Flexible");
		tempRoles2.setRole("Client");
		tempRoles2.setType("Client");
		tempRoles2.setShare((byte) 50);
		tempRoles2.setNo(23333);
		tempRoles2.setName("AB SEB Brålanda");
		
		tempRoles2.setStartDate(new Date(System.currentTimeMillis()));
		tempRoles2.setExpiryDate(new Date(System.currentTimeMillis()));
		
		
		RoleS tempRoles1 = new RoleS();
		tempRoles1.setPolicyNo("22-0033-01");
		tempRoles1.setPolicyStatus("In-Force");
		tempRoles1.setProduct("Flexible");
		tempRoles1.setRole("Client");
		tempRoles1.setType("Client");
		tempRoles1.setShare((byte) 50);
		tempRoles1.setNo(23333);
		tempRoles1.setName("SEB Brålanda");
		
		tempRoles1.setStartDate(new Date(System.currentTimeMillis()));
		tempRoles1.setExpiryDate(new Date(System.currentTimeMillis()));
		
		
		RoleS tempRoles3 = new RoleS();
		tempRoles3.setPolicyNo("22-3333-01");
		tempRoles3.setPolicyStatus("Complete");
		tempRoles3.setProduct("SEB");
		tempRoles3.setRole("Distr");
		tempRoles3.setType("Client");
		tempRoles3.setShare((byte) 50);
		tempRoles3.setNo(2322223);
		tempRoles3.setName("Brålanda");
		
		tempRoles3.setStartDate(new Date(System.currentTimeMillis()));
		tempRoles3.setExpiryDate(null);
		
		
		RoleS tempRoles4 = new RoleS();
		tempRoles4.setPolicyNo("22-0033-01");
		tempRoles4.setPolicyStatus("In-Force");
		tempRoles4.setProduct("Flexible");
		tempRoles4.setRole("Client");
		tempRoles4.setType("Client");
		tempRoles4.setShare((byte) 50);
		tempRoles4.setNo(23333);
		tempRoles4.setName("AB SEB Brålanda");
		
		tempRoles4.setStartDate(new Date(System.currentTimeMillis()));
		tempRoles4.setExpiryDate(new Date(System.currentTimeMillis()));
				
		
		for(int i=0; i<3;i++){
			roles.add(tempRoles1);
			roles.add(tempRoles2);
			roles.add(tempRoles3);
			roles.add(tempRoles4);
		}

		return roles;
		
		
	}
	
	
	
	
	public String tempSearchRoles(){
		return "ActRoleMaster.jsf";
	}
	
	public String getTempViewPolicy(){
		return "ViewPolicy.jsf";
	}
	
	public String getTempViewName(){
		return "ViewName.jsf";
	}
	
	
	public void search(ActionEvent actionEvent) {		
		roles=null;
		roles = getTempRoles();
	}  
	
	
	public String getPolicyNumber() {
		return policyNumber;
	}


	public void setPolicyNumber(String policyNumber) {
		this.policyNumber = policyNumber;
	}


	public SelectItem[] getShareOptions() {
		return shareOptions;
	}


	public SelectItem[] getPolicyStatusOptions() {
		return policyStatusOptions;
	}

	

	public SelectItem[] getTypeOptions() {
		return typeOptions;
	}



	public SelectItem[] getProductOptions() {
		return productOptions;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getNumber() {
		return number;
	}


	public void setNumber(String number) {
		this.number = number;
	}



}

Code: Select all


package search;

import java.sql.Date;
import javax.ejb.Stateless;

@Stateless
public class RoleS {

	private String policyNo;
	private String policyStatus;
	private String product;
	private String role;
	private String type;
	private Byte share;
	private String name;
	private Long no;		//can be PPS, client Id, Dist ID or Agency Id
	private Date startDate;
	private Date expiryDate;
	
	
	
			
	public String getPolicyNo() {
		return policyNo;
	}
	public void setPolicyNo(String policyNo) {
		this.policyNo = policyNo;
	}
	public String getPolicyStatus() {
		return policyStatus;
	}
	public void setPolicyStatus(String policyStatus) {
		this.policyStatus = policyStatus;
	}
	public String getProduct() {
		return product;
	}
	public void setProduct(String product) {
		this.product = product;
	}
	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Byte getShare() {
		return share;
	}
	public void setShare(byte share) {
		this.share = share;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Long getNo() {
		return no;
	}
	public void setNo(long no) {
		this.no = no;
	}
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Date getExpiryDate() {
		return expiryDate;
	}
	public void setExpiryDate(Date endDate) {
		this.expiryDate = endDate;
	}
		
}

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests