Null Value for Row Selection on DataTable

UI Components for JSF
Post Reply
hendrel
Posts: 9
Joined: 05 Oct 2017, 20:52

24 Oct 2017, 10:55

When using the data table row selection feature I keep getting a null value for selection="#{activityBrowser.selectedActivity}". Please assist.

Code: Select all

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<title>Time Billing</title>
	<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
	<ui:composition template="/template/browserTemplate.xhtml">
		<ui:define name="headline">Activity</ui:define>
		<ui:define name="left">
		</ui:define>
		<ui:define name="right">
			<p:commandButton value="Add" action="#{activityBrowser.add}" />
			<p:commandButton value="Edit" action="#{activityBrowser.edit}" />
			<p:commandButton value="Delete" action="#{activityBrowser.delete}" />			
		</ui:define>
		<ui:define name="table">
			<p:dataTable value="#{activityBrowser.activities}" var="activity"
				selectionMode="single" selection="#{activityBrowser.selectedActivity}" rowKey="#{activity.id}">
				<p:column headerText="Activity Name">
					<p:outputLabel value="#{activity.activityName}" />
				</p:column>
			</p:dataTable>
		</ui:define>
	</ui:composition>
</h:body>
</html>

Code: Select all

@Named("activityBrowser")
@ViewScoped
public class ActivityBrowser implements Serializable {

	private static final long serialVersionUID = -7114319946887481014L;

	private List<Activity> activities;
	private Activity selectedActivity;
	
	@EJB
	private CustomerBoundary customerBoundry;
	
	public ActivityBrowser() {
	}
	
	@PostConstruct
	public void init() {
		Customer customer = customerBoundry.findCustomerById(Helper.getCustomerSession().getCustomerId());
		activities = customerBoundry.findActivityByCustomer(customer);
	}

	public String add() {
		return "activityEditor";
	}
	
	public String edit() {
		return "activityEditor?id=" + selectedActivity.getId();
	}
	
	public String delete() {
		return "activityBrowser";
	}	
	
	public List<Activity> getActivities() {
		return activities;
	}

	public void setActivities(List<Activity> activities) {
		this.activities = activities;
	}

	public Activity getSelectedActivity() {
		return selectedActivity;
	}

	public void setSelectedActivity(Activity selectedActivity) {
		this.selectedActivity = selectedActivity;
	}
}
Glassfish 4.1.2
JSF 2.2
PrimeFaces 6.1

chrishj
Posts: 229
Joined: 11 Jul 2011, 21:58
Location: England, Lancashire
Contact:

24 Oct 2017, 11:05

Have you tried with initiating selectedActivity in the post construct method?
PrimeReact: 9.6.0
NextJs: 13.4.12
Theme Apollo v9.0
Database pg 8.8.0
react-hook-form: 7.38.0

hendrel
Posts: 9
Joined: 05 Oct 2017, 20:52

24 Oct 2017, 12:47

I have tried the code below in the @PostConstruct method with no success.

Code: Select all

		
		if (!activities.isEmpty()) {
			selectedActivity = activities.get(0);
		}
Glassfish 4.1.2
JSF 2.2
PrimeFaces 6.1

creon
Posts: 12
Joined: 21 Oct 2015, 12:36

15 Jan 2018, 08:28

I have the same error after updating the libraries.
when I was using primefaces 5.3 everything works fine, since I use the new libraries (primefaces 6.0) I have this error.
Can someone help me?
Primefaces 6.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 69 guests