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 9257249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:08:23+00:00 2026-06-18T12:08:23+00:00

I have a field that has a required attribute. When I press the Accept

  • 0

I have a field that has a required attribute. When I press the Accept button to save some data without entering any value in the field, an error message is displayed. So far so good.
But, if right after that I decide to click on the Cancel button, that error message overrides the confirmation message that is supposed to be displayed inside a <p:dialog/> element.

NOTE: If instead I use the <p:confirmDialog/> component, there seems to be no problem because, I guess, it uses a message="" attribute, no the <p:messages/> tag.

XHTML

<p:dialog>
<p:outputPanel>
      <h:form>

      <h:outputText value="Field:"/>
      <p:inputText id="field" value="" type="text" required="true" requiredMessage="You must complete the field" />                         
      <p:growl id="messages" showDetail="true"/>

      <p:commandButton id="dialogCancel" value="Cancel" oncomplete="confirmCancelDialog.show();"  actionListener="#{controller.addCloseWarn}" />    

      </h:form>
</p:outputPanel>
</p:dialog>

<h:form>
<p:dialog id="confirmCancelDialog" header="Warning!" widgetVar="confirmCancelDialog" modal="true" >                                         
    <p:messages id="closeMessage" showDetail="true" autoUpdate="true" />                                    
    <p:commandButton id="confirm" value="Accept" onclick="..." />  
    <p:commandButton id="decline" value="Cancel" onclick="..." />               
</p:dialog> 
</h:form>

Bean controller

public void addCloseWarn(ActionEvent actionEvent) { 
        FacesContext.getCurrentInstance().addMessage("closeMessage", new FacesMessage(FacesMessage.SEVERITY_WARN, null, 
                          "Are you sure you want to leave the page?")); 
}
  • 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-06-18T12:08:24+00:00Added an answer on June 18, 2026 at 12:08 pm

    Problem with Cancel button is that your form is submitted and validation is executed. You can add process="@this" attribute to commandButton, so other parts of form will not be processed and your addCloseWarn method will be executed.

    I would also add that this is probably not standard use of message tag. It is used to show errors, warning and successful messages, not confirmation questions. So use confirmDialog or use standard dialog with just ordinary text and OK – Cancel buttons.

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

Sidebar

Related Questions

I have got a field that has been setup to allow for Null, but
CSV has field that is being parsed which may or may not have entries
I have a text field that is a date, although sometimes it also has
I have a struct that has a field called type How do i access
A have a JPA entity that has timestamp field and is distinguished by a
I have a MySQL table that has a field of comma separated values. How
I have a table contacts that has a field arrayOfMembers (JSON format) and a
I have a table that has an AUTO_INCREMENT field. Currently, it is also a
I have a SQL database that has a table with a field set to
I have an SQL Server 2005 table that has a varchar(250) field which contains

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.