Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:37:37+00:00 2026-05-31T01:37:37+00:00

I have a form inside a dialog which I close by clicking on commandbutton

  • 0

I have a form inside a dialog which I close by clicking on commandbutton with ajax ,

like this

<h:commandButton value="Add" action="#{myBean.addSomething(false)}"
    id="add_something_id" >
    <f:ajax render="@form someTable" execute="@form"
        onevent="closeAddNewSomethingDialogIfSucceeded"></f:ajax>
</h:commandButton>

and here is the js code for closing the dialog

    function closeAddNewSomethingDialogIfSucceeded(data) {
        if(data.status === 'success') {
            $("#dialog_id").dialog("close");
        }
    }

No problems till here…

Now I changed some of the dialog form fields into required="true" and now I want to prevent the closing of the dialog of i got validation errors…

But the ajax data.status still reaches its success state , and I can’t figure out what indication of validation failure I can hook on…

any ideas?

Thanks to BalusC answer I did the following:

in JSF , added :

    <h:panelGroup id="global_flag_validation_failed_render">
        <h:outputText id="global_flag_validation_failed" value="true" 
            rendered="#{facesContext.validationFailed}"/>
    </h:panelGroup>

the f:ajax was changed into

<f:ajax render="@form someTable global_flag_validation_failed_render"

and in js added the following check

if(data.status === 'success') {
    if($("#global_flag_validation_failed").length === 0){
         $("#dialog_id").dialog("close");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:37:39+00:00Added an answer on May 31, 2026 at 1:37 am

    Not specifically for required="true", but you can check by #{facesContext.validationFailed} if validation has failed in general. If you combine this with checking if the button in question is pressed by #{not empty param[buttonClientId]}, then you can put it together in the rendered attribute of the <h:outputScript> as follows:

    <h:commandButton id="add_something_id" binding="#{add}" value="Add" action="#{myBean.addSomething(false)}">
        <f:ajax execute="@form" render="@form someTable" />
    </h:commandButton>
    <h:outputScript rendered="#{not empty param[add.clientId] and not facesContext.validationFailed}">
        $("#dialog_id").dialog("close");
    </h:outputScript>
    

    (note that you need to make sure that the script is also re-rendered by f:ajax)

    A bit hacky, but it’s not possible to handle it in the onevent function as the standard JSF implementation doesn’t provide any information about the validation status in the ajax response.

    If you happen to use RichFaces, then you could just use EL in the oncomplete attribute of the <a4j:xxx> command button/link. They are namely evaluated on a per-request basis instead of on a per-view basis as in standard JSF and PrimeFaces:

    <a4j:commandButton ... oncomplete="if (#{!facesContext.validationFailed}) $('#dialog_id').dialog('close')" />
    

    Or if you happen to use PrimeFaces, then you could take advantage of the fact that PrimeFaces extends the ajax response with an additional args.validationFailed attribute which is injected straight in the JavaScript scope of the oncomplete attribute:

    <p:commandButton ... oncomplete="if (args &amp;&amp; !args.validationFailed) $('#dialog_id').dialog('close')" />
    

    (note that &amp; is been used instead of &, because & is a special character in XML/XHTML)

    Or you could use the PrimeFaces’ RequestContext API in the bean’s action method to programmatically execute JavaScript in the rendered view.

    RequestContext.getCurrentInstance().execute("$('#dialog_id').dialog('close')");
    

    No conditional checks are necessary as the bean’s action method won’t be invoked anyway when the validation has failed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form inside an iframe which is inside a jQuery UI dialog
Morning. I have a form which is rendered inside of a jquery dialog box
I have a form inside a dialog that appears after clicking in another button.
I have a webrequest that returns a html response which has form inside with
I have to add a textbox inside a form that is composed of a
I have a div inside of a table which is inside of a form
I have the link below that executes the action message/new which shows a form
I have this commandButton : <p:commandButton value=View/Edit onclick=bar.show() oncomplete=bar.hide(); dataSetUserDialog.show(); actionListener=#{dataStoreBean.initUserLists}> <p:ajax event=? update=userSelect
I have a form inside a jquery ui modal dialog, when I click the
I'm using Facebox for my dialog boxes. And I have a create form inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.