Problem with dialog/confirmDialog with dynamic contents

UI Components for JSF
Post Reply
AndreasJ
Posts: 10
Joined: 21 Jun 2011, 10:46

04 Jul 2011, 13:18

I have a datatable and want to show some additional info for each row in a dialog or confirmdialog. This info consists of one or several lines of text, so I wanted to place a datatable inside the confirmdialog/dialog, but I ran into some strange problems, which might be a result of a primefaces error.

The following small example can be used to reproduce the behaviour:

Code: Select all

@Named("testBean")
@SessionScoped
public class TestBean implements Serializable {
	private List<Message> message;
	private String dialogMessage = "New";
	public class Message {
		private String text;
		public Message(String msg) {
			this.text = msg;
		}
		public String getText()	{return text;}
		public void setText(String text) {this.text = text;}
	}

	public String getDialogMessage() {
		return dialogMessage;
	}

	public void settext1() {
		dialogMessage = "button1 clicked";
		message = new ArrayList<Message>();
		message.add(new Message("Button1"));
	}

	public void settext2() {
		dialogMessage = "button2 clicked";
		message = new ArrayList<Message>();
		message.add(new Message("Button2a"));
		message.add(new Message("Button2b"));
	}

	public List<Message> getMessages() {
		return message;
	}
}

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">
	<html><h:head/><h:body>
	<h:form id="form">
		<p:commandButton value="Button1" actionListener="#{testBean.settext1}" oncomplete="dlg.show()"
		 update="XXX">
		</p:commandButton>
		<p:commandButton value="Button2" actionListener="#{testBean.settext2}" oncomplete="dlg.show()"
		 update="XXX">
		</p:commandButton>
	</h:form>
	<h:form id="dlgform">
		<p:confirmDialog id="dlg" message="#{testBean.dialogMessage}" widgetVar="dlg">
			<p:dataTable id="dt" value="#{testBean.messages}" var="dataItem">
				<p:column>
					<h:outputText value="#{dataItem.text}"/>
				</p:column>
			</p:dataTable>
   			<p:commandButton value="Ok" oncomplete="dlg.hide()"/>
		</p:confirmDialog>
	</h:form>
	</h:body></html>
</f:view>
Depending on what I place for update="XXX" in commandButton Button1 and Button2, I expect different behaviour, but I get something unexpected:
  • update="dt": the message of the dialog should stay the same ("New" - the value on first rendering the page), but the datatable should show one or two rows, depending on which button was clicked. Instead I get an empty datatable, no matter what I click.
  • update="dlg": the message should reflect the clicked button and the datatable should show one or two rows of text, instead the message still reads "New" and the datatable is empty - no matter which button and how often I click. That is probably the same problem Ryland has in InputText in dialog not being updated when dialog is shown .
  • update="dlgform": the complete form with the confirmDialog should get updated and indeed now I get a dialog with the expected contents, but I get multiple instances (you might need to move the dialog to see the other one behind it). Each click on a button adds one instance. It looks like the old instances don't get removed by primefaces.
The following javascript function removes the surplus instances of the dialog, when it is called in oncomplete of Button1 and Button2. But this is a very ugly hack to work around a possible primefaces error.

Code: Select all

<script>
<!--
function TestDelete() {
	for (i = document.getElementsByTagName("div").length - 1; i >= 0; i = i - 1) {
		if (document.getElementsByTagName("div").item(i).parentNode.localName == "body") {
			alert(i + " " + document.getElementsByTagName("div").item(i).parentNode.localName);
			itemParent = document.getElementsByTagName("div").item(i).parentNode;
			itemDrop = document.getElementsByTagName("div").item(i);
			itemParent.removeChild(itemDrop);
		}
	}
	dlg.show();
}
-->
</script>
We are using primefaces 3.0M1, JBoss 6.0.0final, mojarra 2.0.3 (b5) and tested with Firefox 5.0 and InternetExplorer 8.
Is this really a primefaces error and shall I open a bug report, or is it the fault of some other component, e.g. user error :) ?

best regards
Andreas

AndreasJ
Posts: 10
Joined: 21 Jun 2011, 10:46

04 Jul 2011, 16:42

Hello again,

following up to your own post may be considered bad style. But jtrotman found and posted a solution for my problem in the other thread, that I wanted to share here:
It is possible to start the h:form inside the p:confirmDialog to avoid these problems. It is not possible to update direct attributes of the confirmdialog, e.g. header and message this way. But I can get away by using "this entry" instead of "entry #x" in the message.

Thanks again jtrotman.

I will not open a bug report for this issue (unless requested) as it turned out as user error after all.

Andreas

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

04 Jul 2011, 18:06

It is not possible to update direct attributes of the confirmdialog, e.g. header and message this way.
Yes, it's not possible with PrimeFaces (limitation), but you can overwrite command button / link / dialog / confirm dialog and update header / message on the client side only - without any ajax requests. I use this technique with two last stable releases (ca. 1 year) and I'm waiting for accepting this from the PrimeFaces team. It should be possible to update message text in dialogs without roundtrip and that is a big advantage (e.g. for row selection and any kind of "Are you sure you want to delete XYZ?"). And I know it's not difficult to implement because we use this already a long time in two projects. Create an issue or make it self.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

burferd
Posts: 234
Joined: 01 May 2010, 16:15

18 Jul 2011, 23:31

Not being able to dynamically set the content of the dialog / confirm dialog is REALLT A BIG LIMITATION.

Being able to push a button, do some process and display the results in a dialog or confirmDialog is something that I have beat my head against for a while.
Static content is pretty useless, really.
I finally just gave up and wrote my own version of a modal popup to take care of this issue.

Is there a reason that the the dialog / confirmDIalog cannot be repackaged to allow dynamic content update?

Any chance of getting that on a wish list?

Thanks.
Using PrimeFaces 3.4, Mojarra 2.1.6, Glassfish 3.1.2, NetBerans 7.2, Hibernate 3.2.5 (sometimes)
Windows 7.

hfcprime
Posts: 108
Joined: 22 Feb 2011, 20:32

19 Jul 2011, 04:03

I agree on the importance of this. Thanks for the Javascript, I tried various other things without success.
ENVIRONMENT
Angular 5.2.4, CLI 1.6.8, PrimeNG 5.2.0, Chrome 64.0.3282.186, Angular CLI project in Webclipse IDE, Win 10 Pro

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests