Changing variable from DataTable in Dialog

Components, Ajax Framework, Utilities and More.
Post Reply
User avatar
vizzdoom
Posts: 4
Joined: 17 Nov 2011, 22:54
Location: Poland
Contact:

17 Nov 2011, 23:40

Hello PrimeFaces!

I have a question about updating variable inside dataTable component, which was sended to dialog component.

I want to have dialog box with options. There are informations about user (user data editing).
ManageUsers class have UserDAO selectedUser property, UserDAO class contains User POJO (login, email etc).
ManageUsers.updateUser persists data in database.

How can I update selectedUser through inputText?
I can not use p:inplace component because I have a problem with h:forms and facelets (changing to production stage does not resolve this problem).

Glassfish: 3.1
Primefaces: 2.2
JSF: 2.1 (now MyFaces 2.1.3)

Code: Select all

 <h:form prependId="false">  

	<p:growl id="growl"/>

	<!--            Data table with all users-->
	<p:dataTable id="userTable" var="u" value="#{manageUsers.users}">  

		<p:column headerText="login" style="width:150px" filterBy="#{u.user.login}" filterMatchMode="contains">  
			<h:outputText value="#{u.user.login}" />
		</p:column>  

		<p:column headerText="email" style="width:150px" filterBy="#{u.user.email}" filterMatchMode="contains">  
			<h:outputText value="#{u.user.email}" />  
		</p:column> 

		<p:column headerText="apikey" style="width:150px" filterBy="#{u.user.apikey}" filterMatchMode="startsWith">  
			<h:outputText value="#{u.user.apikey}" />
		</p:column> 

		<p:column headerText="Options" >  
			<p:commandButton update="display" oncomplete="userDialog.show()"  
							 image="ui-icon ui-icon-search">  
				<f:setPropertyActionListener value="#{u}" target="#{manageUsers.selectedUser}" />  
			</p:commandButton>  
		</p:column>  

	</p:dataTable>   

	<!--            Dialog box with options-->
	<p:dialog appendToBody="true" header="User Detail" widgetVar="userDialog" resizable="false"  
			  width="500" showEffect="explode" hideEffect="explode" onCloseUpdate="growl,userTable">  
		<h:panelGrid id="display" columns="2" cellpadding="4">  

			<h:outputText value="Login" />
			<p:inputText  required="true" value="#{manageUsers.selectedUser.user.login}" />

			<h:outputText value="Email" />
			<p:inputText  required="true" value="#{manageUsers.selectedUser.user.email}" />
			
			<p:commandButton value="save and exit" action="#{manageUsers.updateUser}" update="growl" onclick="userDialog.hide()" />

		</h:panelGrid>  
	</p:dialog>

</h:form>
Image

bpap
Posts: 34
Joined: 30 Sep 2011, 16:15

18 Nov 2011, 00:44

I think you only need to update userTable too:
<p:commandButton value="save and exit" action="#{manageUsers.updateUser}" update="growl,userTable" onclick="userDialog.hide()" />
Apache Tomcat 7.0.21 / JSF 2.1.2 / PM 3.0.M4-SNAPSHOT

User avatar
vizzdoom
Posts: 4
Joined: 17 Nov 2011, 22:54
Location: Poland
Contact:

26 Nov 2011, 10:28

Unfortunately, it does not work. The element is not in the bean (CDI). I have no idea how to update this variable (persist in database).

User avatar
vizzdoom
Posts: 4
Joined: 17 Nov 2011, 22:54
Location: Poland
Contact:

27 Nov 2011, 16:39

PROBLEM RESOLVED. Setters was not fired. I don't know why, but when I remove appendToBody="true", then setters work perfectly. Anyone know why?

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 Nov 2011, 04:09

Based on my experience,

1. appendToBody="true" appends your p:dialog at the end of the html <body> of your html page
2. appendToBody="false" embeds your p:dialog and p:dataTable in the same h:form tag
3. the h:form tag is required for (and/or helps) AJAX/PrimeFaces processing

Code: Select all

<h:form prependId="false">  

   <p:growl id="growl"/>

   <!--            Data table with all users-->
   <p:dataTable id="userTable" var="u" value="#{manageUsers.users}">  


   <!--            Dialog box with options-->
   <p:dialog appendToBody="true" header="User Detail" widgetVar="userDialog" resizable="false"  
           width="500" showEffect="explode" hideEffect="explode" onCloseUpdate="growl,userTable">  

</h:form>
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

User avatar
vizzdoom
Posts: 4
Joined: 17 Nov 2011, 22:54
Location: Poland
Contact:

28 Nov 2011, 11:21

Thanks.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 6 guests