Primefaces Dialog and Closable events

UI Components for JSF
User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

17 May 2011, 22:25

There is a long time that I am trying to solve some problems of using Primefaces dialog.

Searching on Google, forums and without any answer that solves the problem from a non intrusive way.

The problem is how to maintain opened a Dialog if one of it inputs inside them has errors like a message sent to a required field.
One of the solutions that I have found was the use of a faces parameter on the visibility of the Dialog, but with this, I can not use the "modal=true" because with this, I need to refresh the whole page to reopen the same dialog.

http://www.martinahrer.at/2009/12/03/cl ... available/

The other solution that works for me was the Javascript implementation, suggested by Oleg.

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

But I have a question. If my application commonly uses dialogs, I will need to have this Javascrip imported on all pages and to verify all my Backing Beans to pass the "args" parameter that will tell if my dialog can or not be closed.

I don't think this is a good solution, it is against all the Idea of usability and simplicity proposed by Primefaces and JSF2.0.

What do you think about it?
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

artursampaio
Posts: 3
Joined: 18 Feb 2011, 19:54

21 May 2011, 04:53

I absolutely agree with you.

My user interface is based on pages with lists of records (datatable) and popup (dialog) windows for adding or editing records (form).
When the form is submited the application needs to control whether to still showing or not the dialog, considering the fields validations.

Looking for a solution on the web, i've found the same way as you, with the javascript code
I really don't like this kind solution. Maybe there's a better way to control the dialog visibility, base on faces messages.

Actually i´m wondering that this behavior could be implemented in the component itself.

Is anybody else experiencing problems like these?

Best Regards,
Primefaces 2.2 - JSF 2.0 - Glassfish Server 3 - Netbeans 6.9.1

Alex
Posts: 256
Joined: 16 Dec 2010, 14:24
Location: Germany

21 May 2011, 09:29

We are using a similar way via javascript in our application and see no problem with this..
PF is using JS massivly, so why should this be a break?

to be more dynamic, we solved this with a phaselistener, which sets the callback param if a message of specific severity is there.
we just have to call a JSmethod like "hideModalPanel(xhr, status, args, dialogId)" to react on this in the oncomplete part of the buttons..
Due to our styleguide, no dialog in our application is closeable via the closebutton or ESC. Cancel and submit buttons in the footer are the only ways to close the dialog and both buttons use our hideModalPanel method to do so.
But I have a question. If my application commonly uses dialogs, I will need to have this Javascrip imported on all pages and to verify all my Backing Beans to pass the "args" parameter that will tell if my dialog can or not be closed.
Yes it has to be included in every single page. We are using templates so this is no problem, is it?

Of course it would be nice if the component has a way to handles this by itself and i probably would use it, but due to very specific demands i think its kind of hard to implement
PrimeFaces 3.2
Mojarra 2.0.2
Glassfish 3.0.1

artursampaio
Posts: 3
Joined: 18 Feb 2011, 19:54

21 May 2011, 16:13

Alex,
Thanks for your reply

There's no problem about using the JS technology inside PF, but i think it should be under the hood, transparently to the developer. Just like the other components.

Your PhaseListener appears to be a nice solution, could you share the source with us?

I guess the dialog component needs to be reviewed, cause I'm experiencing another issue on it:
reopening the dialog sucessive times (multiple records editing), causes the inner components to be unstable. picklist is my worst case, because it starts to duplicate entries.
Looks like other users experienced this problem too:
http://primefaces.prime.com.tr/forum/vi ... +duplicate
http://primefaces.prime.com.tr/forum/vi ... ate#p31707

Looks like the request becomes infected after the first data validation.

I´m myself a volunteer to help with this code review, as soon I understand the PF source architecture and implementation rules. I´m studying this right now. Links for documentations are welcome! :)

Best regards,

Artur Sampaio
Primefaces 2.2 - JSF 2.0 - Glassfish Server 3 - Netbeans 6.9.1

User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

23 May 2011, 14:30

Hello Alex,

Thanks for your help!
Here we are using templates too. My post was Just to open a discussion about the way like the dialog has your events called.
And how you said, it Would be nice if the components had a way to control at least the errors messages by itself.

I'm trying to include the JS function and change the dialogs of my application to this new way.
I'll appreciate if you share your PhaseListener with us. Can you do that please?

Thanks in advance.
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

Alex
Posts: 256
Joined: 16 Dec 2010, 14:24
Location: Germany

24 May 2011, 09:36

hi there... this is the listener:

Code: Select all

public class MessageOccuredPhaseListener implements PhaseListener {

    @Override
    public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

    @Override
    public void beforePhase(PhaseEvent event) {
        RequestContext context = RequestContext.getCurrentInstance();
        if (context != null) {
             boolean messageOccured = FacesMessage.SEVERITY_ERROR.equals(event.getFacesContext().getMaximumSeverity());
            context.addCallbackParam("messageOccured", messageOccured);
        }
    }

    @Override
    public void afterPhase(PhaseEvent event) {}

}
note that you have to register your listener in the faces-config

with that you can easily check before closing the dialog:

Code: Select all

function hideDialog(xhr, status, args, dialogWidgetVar) {
    if(!args.validationFailed && !args.messageOccured) {
        dialogWidgetVar.hide();
    }
}
note that this only fits to buttons you can access.. in our application every dialog is not closeable with the dialogs close button or ESC (closable="false" closeOnEscape="false")
i dont know if this can also be bound on the closebutton, cause we did not need that
PrimeFaces 3.2
Mojarra 2.0.2
Glassfish 3.0.1

User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

24 May 2011, 19:47

Hello Alex,

Thanks for your reply.
I did the PhaseListener here with the JS Solution and almost everything work's fine.
Now I have another problem. My dialog has two buttons. One to save and other to cancel.

On the save Button I call the JS that in success case closes the dialog or in other case, shows me the errors messages.
On the cancel Button I just close the dialog. The problem is, if I send the data to save and a error is found, my dialog will show the errors, but if I click on cancel button to close the dialog, when I reopen it, the typed data is still there. I want my dialog clear after a cancelled operation.
I tried to call a Backing Bean method to reinitialize the objects but without success, the typed data still on my dialog, so I tried to clean the components with a UIComponent. getChildren().clear(); and the problem persists.
So, did you have any Idea how can I clear the form data if I cancel the dialog?
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

Alex
Posts: 256
Joined: 16 Dec 2010, 14:24
Location: Germany

24 May 2011, 21:53

therefor we always have a init method which is called before opening the dialog. Maybe you just forgot to update the dialogs content after resetting it?

i will give you an example:
a button can look like this (I write it out of the head):

Code: Select all

<p:commandButton value="open dialog" actionListener="#{myBean.actionInitDialog}" update="myDialog:contentWrapper"  oncomplete="myDialogWV.show()" />
The initmethod resets all necessary data in the bean and after that the update to an inner wrapper of the dialog (attention: never ever update a dialog itself or one of its parents!!).
attention: the .show() has to be called in oncomplete, so actionListener and update are finished before.

the dialog may look like this:

Code: Select all

<p:dialog id="myDialog" widgetVar="myDialogWV">
<p:outputPanel id="contentWrapper">
[... some content ...]
</p:outputPanel>
</p:dialog>
PrimeFaces 3.2
Mojarra 2.0.2
Glassfish 3.0.1

User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

24 May 2011, 22:26

Here too.
Before any kind of event called in our application we make use of a initMethod that resets all data of the dialog.

Our system are looking basically like yours.
All things are make on the same way. We first call the actionListener and update. The onComplete can only open or hide a dialog.

If I debug my application, the bean is empty, it seems that the data typed in the inputs, are still on the GUI from a misterious way.
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1

Alex
Posts: 256
Joined: 16 Dec 2010, 14:24
Location: Germany

24 May 2011, 23:11

well, when the actionListener ist invoked correctly, i guess it has to be the update. Maybe just a typo or something.
Perhaps you can post the opening button and the basic dialog structure?
PrimeFaces 3.2
Mojarra 2.0.2
Glassfish 3.0.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests