0

The page has a data entry form. Clicking on a command button the data is entered into the database.

I need to define a way to control data via a function of the bean, and if this data is already in the database (eg: the function of the bean that controls this returns false), bring up a dialog to choose whether to overwrite the data or cancel the operation (overwriting should be performed always by a bean method).

How can I handle this? I use JSF and Primefaces.

EDIT:

I've tried with RequestContext but the dialog does not appear. The dialog is this:

<p:commandButton id="tasto" value="Insert"
                action="#{bean.prova()}" update="BankGrid errorbank" ajax="false" />
            <p:dialog id="dialog" header="Title" widgetVar="dlg" resizable="false">
                <h:panelGrid>
                    <h:outputLabel value="Wanna do?" />
                    <p:commandButton id="button" value="YES"
                        action="#{bean.insertExist()}" ajax="false" />
                    <p:commandButton value="NO"
                        action="back.xhtml?faces-redirect=true" />"
                 </h:panelGrid>
            </p:dialog>

All inside a form, and the function is this:

public void prova(){
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('dlg').show();");

}

What's wrong?

3
  • What is wrong? : you not using ajax and expecting a dialog to show up after a full refresh of the page. This only works when you use ajax (as you can see ij the pf showcase since examples like this are (afaik) in the ajax group of examples. So switch to using ajax and it works
    – Kukeltje
    Feb 20, 2015 at 23:20
  • Without the flag ajax it works. Thank you
    – BillB
    Feb 20, 2015 at 23:39
  • In the future, please immediately post a stackoverflow.com/help/mcve, particularly if you're doing things differently from defaults.
    – BalusC
    Feb 23, 2015 at 8:01

1 Answer 1

3

Depends on how you're submitting the form.

If you're submitting the form by ajax, use RequestContext#execute() to programmatically execute a script on complete of ajax submit:

So, given a

<p:dialog ... widgetVar="fooDialog">

you can programmatically open it via:

if (someCondition) {
    RequestContext.getCurrentInstance().execute("PF('fooDialog').show()");
}

Or, if you're submitting the form synchronously (i.e. you're using ajax="false" for some reason), then use the visible attribute:

<p:dialog ... visible="#{bean.someCondition}">
3
  • To do this I need to create a navigator? (or create the faces-config.xml)? I tried but it does not work
    – BillB
    Feb 20, 2015 at 18:36
  • As posted above, it only works in non ajax requests @balusc: can you add this in the answer. I tried to propose a small edit, but it still said the answer changed to much
    – Kukeltje
    Feb 20, 2015 at 23:52
  • @balusc: Dank… BillB: please accept the answer so for others seachring for similar things, it is clear there is a valid and correct answer
    – Kukeltje
    Feb 21, 2015 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.