DataTable incell editing

UI Components for JSF
Post Reply
wobblycogs
Posts: 47
Joined: 19 Apr 2010, 19:09
Location: Gloucester, UK

07 Mar 2011, 19:19

Hi,

I must be doing something really stupid because I can't seem to get incell editing to work for my DataTable despite banging my head on the problem all afternoon - sigh.

The data table

Code: Select all

<p:dataTable var="setting" value="#{systemSettingView.getSystemSettings( moduleName )}"
					 rowEditListener="#{systemSettingView.rowEdit}" onRowEditUpdate="messages">
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{msg.name}"/>
				</f:facet>
				<h:outputText value="#{msg[setting.name.resourceName]}"/>
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{msg.value}"/>
				</f:facet>
				<p:cellEditor>
					<f:facet name="output">
						<h:outputText value="#{setting.value}"/>
					</f:facet>
					<f:facet name="input">
						<p:calendar value="#{setting.date}" rendered="#{setting.name.type == 'DATE'}" effect="fade" navigator="true"/>
						<p:spinner value="#{setting.integer}" rendered="#{setting.name.type == 'INTEGER'}"/>
						<p:spinner value="#{setting.long}" rendered="#{setting.name.type == 'LONG'}"/>
						<p:inputText value="#{setting.value}" rendered="#{setting.name.type == 'STRING'}"/>
						<p:inputText value="#{setting.double}" rendered="#{setting.name.type == 'DOUBLE'}"/>
					</f:facet>
				</p:cellEditor>
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{msg.description}"/>
				</f:facet>
				<h:outputText value="#{msg[setting.name.resourceDescription]}"/>
			</p:column>
			<p:column>
				<p:rowEditor/>
			</p:column>
		</p:dataTable>
The rowEdit method in systemSettingsView

Code: Select all

public void rowEdit( RowEditEvent event ) {
		SystemSetting setting = (SystemSetting)event.getObject();
		logger.info( "Updating: {}", setting.toString() );
		systemSettingService.update(setting);
	}
The call to event.getObject is returning the correct SystemSetting but the state of the setting is as it was before the user changed it - clearly I wan't to persist the results of the users changes. How can I access the updated state of the object?

Cheers, guys :D
PrimeFaces 3.0.1, Mojarra 2.1.3, GlassFish 3.1.1, Netbeans 7.0, Firefox 7

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

08 Mar 2011, 15:49

What version of PrimeFaces are you using? There was a bug a very long time ago where the edit event was called during the wrong phase of the JSF lifecycle:

http://primefaces.prime.com.tr/forum/vi ... f=3&t=5250

It is unlikely that is your problem though (because I doubt you're using a version that old).

I noticed that you've got multiple UIInput components in a single cellEditor. I'm not sure if that is a problem or not, but I've never seen that before so you might try limiting your cellEditor to a single UIInput and see if that changes things.

Also, what scope is your backing bean? Try session if you haven't already.

wobblycogs
Posts: 47
Joined: 19 Apr 2010, 19:09
Location: Gloucester, UK

08 Mar 2011, 16:41

Thanks for the help Bumble Bee, I was going to thank you anyway because I (eventually) figured out what the problem was and it was one of your posts that gave me the answer. I made a silly noob' mistake: my getter method kept going back to the database to get the values on each call so the users modifications were being over written. For anyone following up on this the threads that provided the solution are here http://primefaces.prime.com.tr/forum/vi ... f=3&t=5250 and here http://primefaces.prime.com.tr/forum/vi ... f=3&t=5239.

If you would be so kind as to give me a hint as to how I should solve the new problem this fix has caused though I would be very grateful...

This is the setup I have now: my backing bean is session scoped. A List<SystemSetting> is now populated in a method marked with @PostConstruct so the backing bean getter always returns the same list of objects every time. The multiple UIInput components works fine and updates are correctly detected and written back to the database.

However, since the backing bean is now session scoped the List<SystemSetting> is being populated once when the bean is first created and is going stale over time as other users make changes. Re-loading the page obviously doesn't help because the bean is longer scoped so the list will always be as it was when first loaded. What I'm asking, I suppose, is how do I re-populate the list when the page is refreshed? I'm going to have a read up on conversation scope to see if that will help.

Thanks again.
PrimeFaces 3.0.1, Mojarra 2.1.3, GlassFish 3.1.1, Netbeans 7.0, Firefox 7

wobblycogs
Posts: 47
Joined: 19 Apr 2010, 19:09
Location: Gloucester, UK

08 Mar 2011, 17:08

Ignore me :D

I just dropped the backing bean down to request scope and it works fine now. The updates are happening without a full page refresh so the backing bean is still available to handle the individual row updates but the list is correctly recreated on a page refresh.

Thanks again for the help.
PrimeFaces 3.0.1, Mojarra 2.1.3, GlassFish 3.1.1, Netbeans 7.0, Firefox 7

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

08 Mar 2011, 19:36

Glad you got it working.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests