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

  • Home
  • SEARCH
  • 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 8453667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:49:17+00:00 2026-06-10T11:49:17+00:00

Consoder the following code: <h:commandButton value=do action=#{testBacking.do}> <f:ajax execute=@all render=@all listener=#{testBacking.listener}/> </h:commandButton> I want

  • 0

Consoder the following code:

<h:commandButton value="do" action="#{testBacking.do}">
   <f:ajax execute="@all" render="@all" listener="#{testBacking.listener}"/>
</h:commandButton>

I want to have a custom tag (with value based on server logic), in the Ajax response XML, something like the following:

<isValidationFailed> true </isValidationFailed>

I can use this data to re-enable the button (which was disabled when Ajax begin, to avoid double clicks) if validation is failed.

How can I achieve this (preferably without using any JSF 3rd party libraries)?

EDIT:

The example code, more precisely, should be like this:

<h:commandButton id="myButton" value="do" action="#{testBacking.do}">
 <f:ajax execute="id1" render="id2 myButton" listener="#{testBacking.listener}"/>
</h:commandButton>
  • 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-10T11:49:18+00:00Added an answer on June 10, 2026 at 11:49 am

    This is only possible with a custom PartialViewContext which you load into your JSF application using a PartialViewContextFactory. The custom PartialViewContext should in turn return a custom PartialResponseWriter on PartialViewContext#getResponseWriter(). In this custom PartialResponseWriter, you should be able to add extensions to the XML response by calling startExtension() and endExtension() in endDocument(). Something like:

    @Override
    public void endDocument() throws IOException {
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put("name1", "value1");
        attributes.put("name2", "value2");
        startExtension(attributes);
        write("lorem ipsum");
        endExtension();
        super.endDocument();
    }
    

    This will then end up in the XML response as

    <extension name1="value1" name2="value2">lorem ipsum</extension>
    

    This is available and traversable by data.responseXML in jsf.ajax.addOnEvent() function.


    Here’s a full kickoff example how you could utilize it in your particular case:

    MyPartialViewContextFactory which provides the custom partial view context:

    public class MyPartialViewContextFactory extends PartialViewContextFactory {
    
        private PartialViewContextFactory wrapped;
    
        public MyPartialViewContextFactory(PartialViewContextFactory wrapped) {
            this.wrapped = wrapped;
        }
    
        @Override
        public PartialViewContext getPartialViewContext(FacesContext context) {
            return new MyPartialViewContext(wrapped.getPartialViewContext(context));
        }
    
    }
    

    MyPartialViewContext which provides the custom partial response writer:

    public class MyPartialViewContext extends PartialViewContextWrapper {
    
        private PartialViewContext wrapped;
        private PartialResponseWriter writer;
    
        public MyPartialViewContext(PartialViewContext wrapped) {
            this.wrapped = wrapped;
            this.writer = new MyPartialResponseWriter(wrapped.getPartialResponseWriter());
        }
    
        @Override
        public PartialResponseWriter getPartialResponseWriter() {
            return writer;
        }
    
        @Override
        public void setPartialRequest(boolean isPartialRequest) {
            wrapped.setPartialRequest(isPartialRequest);
        }
    
        @Override
        public PartialViewContext getWrapped() {
            return wrapped;
        }
    
    }
    

    MyPartialResponseWriter which writes <extension id="myextension"> with the body as JSON):

    public class MyPartialResponseWriter extends PartialResponseWriter {
    
        public MyPartialResponseWriter(ResponseWriter wrapped) {
            super(wrapped);
        }
    
        @Override
        public void endDocument() throws IOException {
            startExtension(Collections.singletonMap("id", "myextension"));
            write("{\"validationFailed\": " + FacesContext.getCurrentInstance().isValidationFailed() + "}"); // Consider a JSON serializer, like Google Gson.
            endExtension();
            super.endDocument();
        }
    
    }
    

    To get it to run, register the factory as follows in faces-config.xml:

    <factory>
        <partial-view-context-factory>com.example.MyPartialViewContextFactory</partial-view-context-factory>
    </factory>
    

    Here’s how you can access, parse and use the <extension id="myextension"> in your jsf.ajax.addOnEvent():

    jsf.ajax.addOnEvent(function(data) {
        if (data.status == "success") {
            var args = JSON.parse(data.responseXML.getElementById("myextension").firstChild.nodeValue);
    
            if (args.validationFailed) {
                // ...
            }
            else {
                // ...
            }
        }
    });
    

    However, your particular functional requirement can be achieved in a different, likely simpler, manner. Just let the ajax request update the button itself and let the button’s disabled attribute evaluate true when there’s means of a successful postback.

    <h:commandButton id="myButton" value="do" action="#{testBacking.do}" 
        disabled="#{facesContext.postback and not facesContext.validationFailed}">
        <f:ajax execute="id1" render="@this id2" listener="#{testBacking.listener}"/>
    </h:commandButton>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: // MyClass.h @interface MyClass @property NSInteger Value; @end //MyClass.m @implementation
I have a question regarding exception handling. Consider following Java code snippet. try{ //code
Consider following code, I want to make it a thread safe class, so that
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider following code: enum size = 16; double[size] arr1 = [...]; double[size] arr2 =
Please consider following code: 1. uint16 a = 0x0001; if(a < 0x0002) { //
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
Consider the following code: public interface A { public A another(); } public interface
Consider the following code: $xml = <<<XML <root> <region id='thisRegion'></region> <region id='thatRegion'></region> </root> XML;

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.