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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:44:26+00:00 2026-06-16T19:44:26+00:00

In a JSF 2.1 wep app, I have a column of a dataTable that

  • 0

In a JSF 2.1 wep app, I have a column of a dataTable that contains a commandButton. The action triggered by the commandButton may throw an error. I want to open a dialog in case no errors are thrown, or a box containing the error message in the other case.

JSF

<h:form>
    <p:dataTable var="foo" value="#{myBean.foos}" >
        <p:column>#{foo.id}</p:column>
        <p:column>
            <p:commandButton title="Action" action="#{myBean.action()}" onComplete="handleResult(xhr, status, args)" >
                <f:setPropertyActionListener value="#{foo}" target="#{myBean.selectedFoo}" />
            </p:commandButton>
        </p:column>
    </p:dataTable>
</h:form>

JavaScript

function handleRequest(xhr, status, args) {
    if (!args.success) {
        displayBox(args.errorMsg);
    } else {
        displayDialog();
    }
}

MyBean

@ManagedBean
@ViewScoped
public class MyBean {
    private List<Foo> foos;
    private Foo selectedFoo;

    public void action() {
        try {
            // business logic
        } catch (Exception ex) {
            RequestContext rContext = RequestContext.getCurrentInstance();
            rContext.addCallbackParam("success", false);
            rContext.addCallbackParam("errorMsg", ex.getMessage());
        }
    }
}

The only solution I can think of is using PrimeFaces’ RequestContext.callBackParam() and writing a JS function that reads it and decides what to open.

Is there a smoother way? I’d consider to leverage the concept of validation, if possible, but I can’t find an example of how to intercept the error in JS.

  • 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-16T19:44:26+00:00Added an answer on June 16, 2026 at 7:44 pm

    The canonical way is to just add a global faces message (thus, with null client ID).

    public void action() {
        try {
            // business logic
        } catch (Exception ex) {
            context.validationFailed();
            context.addMessage(null, new FacesMessage(
                FacesMessage.SEVERITY_ERROR, ex.getMessage(), null));
        }
    }
    

    (calling FacesContext#validationFailed() will cause #{facesContext.validationFailed} in EL to evaluate true; this is normally set in case of ValidatorException)

    Then, to display a box for global message only, just use <p:messages globalOnly="true">.

    <p:messages globalOnly="true" autoUpdate="true" />
    

    And to display a dialog on successful outcome, let it render when a successful postback is performed:

    <p:outputPanel autoUpdate="true">
        <p:dialog visible="true" rendered="#{facesContext.postback and not facesContext.validationFailed}">
            A successful postback is performed!
        </p:dialog>
    </p:outputPanel>
    

    Replace if necessary autoUpdate="true" of one or the both components by update="messagesId dialogPanelId" so that it’s only triggered when the particular button is pressed.

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

Sidebar

Related Questions

(Using jsf-2) I have a dataTable with one column which can be edited: <h:column>
I have a JSF page that is included in other JSF pages (basically a
I'm using JSF/ICEFaces. I have a table that have many rows with values and
Explanation: I have a JSF command link that sets a member in the backing
When you use JSF, you'll have the controller servlet javax.faces.webapp.FacesServlet that will be mapped
I am using JSF 2.0 and I have a datatable which gets populated using
In JSF is it possible to have a datatable displays records as follows? [Name
my JSF web app is giving randomly error: zip file closed when accessing files
Have JSF 1.2 two pages(one.xhtml and other.xhtml), that are included to the current page
In JSF 2 you can pass around ids, Strings other things that can be

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.