partial-response status code

UI Components for JSF
Post Reply
s4p
Posts: 2
Joined: 28 Jan 2019, 19:16

11 Oct 2019, 19:49

Hello,

I have a question regarding the partial-response HTTP status code. A part of my page looks like this:

Code: Select all

<p:inputText value="#{myJsfBean.myInput01}" />
<p:commandButton  value="Do Something" action="#{myJsfBean.doSomething}" partialSubmit="true" onsuccess="goToNext()" onerror="displayError()" />
In my backing bean the doSomething method is processing the input value and it may happen that an Exception is thrown.

Code: Select all

    private String myInput01;
    (getter and setter)
    
    public void doSomething() {
    	if(myInput01 == "bad value") {
    		throw new IllegalArgumentException();
    	}else {
    		// do something
    	}
    }
The HTTP status code of the partial-response is always 200 and the onerror is never called. The only way I could manage a HTTP status e.g. 400 was doing this:

Code: Select all

   
    public void doSomething() {
    	if(myInput01 == "bad value") {
		ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
		HttpServletResponse response = (HttpServletResponse) context.getResponse();
		response.setStatus(400);
    	}else {
    		// do something
    	}
    }
But I do not want to place this code in every possible method. How can I set the system to response with e.g. 400 when specific Exceptions are thrown?

Best regards
Michael

kukeltje
Expert Member
Posts: 9406
Joined: 17 Jun 2010, 13:34
Location: Netherlands

13 Oct 2019, 19:08

Use a good exceptionhandler for this like the one in PrimeFaces or Omnifaces. The 'onError' should not be used for this. It was not its intention.
Ronald van Kuijk
______________________________
PrimeFaces 6.1, PrimeFaces plus 0.0.2 | JbossWildfly 10.1| Mojarra 2.2.13
Fedora 61, Firefox 'most recent'
Read the forum posting rules
Beginners: https://jsf.zeef.com/bauke.scholtz

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests