0

I've a problem with a bean that doesn't dispatch the response to another page. This is the code:

        @ManagedBean(name = "ssoServiceBean")
    public class SSOServiceBean {

        @ManagedProperty(value="#{param.samlRequest}")
        private String samlRequest;

        @ManagedProperty(value="#{param.relayState}")
        private String relayState;


        @PostConstruct
        public void submit() {

            System.out.println("1) PostConstruct method called");

            //samlRequest = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("samlRequest");

            //relayState = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("relayState");        

            processResponse();
        } 

 //getters and setters omitted for succinctness

        private void processResponse(){

            System.out.println("2) Processing response");

            String uri;

            if(samlRequest != null && !samlRequest.equals("") && relayState != null && !relayState.equals("")) {

                System.out.println("SAMLRequest: "+samlRequest);
                System.out.println("RelayState: "+relayState);

                uri = "challenge.xhtml";

                System.out.println("3) Sending challenge...");  

            } else {

                uri = "dashboard.xhtml";

                System.out.println("3) Sending dashboard...");
            }

            try {
                FacesContext.getCurrentInstance().getExternalContext().dispatch(uri);
                System.out.println("4) Done.");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

The problem is that the dispatch() method doesn't work properly, and seems to be ignored.

Infact the system responses with an error of the related bean's page ssoservice.xhtml

I've used the Postconstruct annotation because with this bean I've to intercept POST parameters that come from a third-party page. Once I've received the post parameters, I've to render the challenge.xhtml page, WITHOUT using a redirect directive.

Nextly, the user will submit challenge.xhtml to the related bean ChallengeBean.java .

So, what is the problem? Why dispatch doesn't work?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Check this http://stackoverflow.com/questions/14163457/externalcontext-dispatch-not-working check if its a `ajax` request – Subodh Joshi Aug 12 '15 at 09:27
  • @SubodhJoshi I'm not using ajax functionalities –  Aug 12 '15 at 09:30
  • 1
    Then check this http://stackoverflow.com/questions/15108896/externalcontextdispatch-doesnt-work – Subodh Joshi Aug 12 '15 at 09:33
  • @Subodh Joshi, your solution doesn't work. My bean reponses its page, and doesn't render challenge.xhtml –  Aug 12 '15 at 10:07
  • @BalusC, your solution doesn't work. My bean reponses its page, and doesn't render challenge.xhtml –  Aug 12 '15 at 10:07
  • @BalusC No one... Could be a problem I'm using PostConstruct annotation? –  Aug 12 '15 at 10:19
  • @BalusC PostConstruct works properly in order to intercept post parameters from a form that comes from an external site (form's action is my bean's url). But from the bean, I cannot render challenge.xhtml view The submitter form is a simple html form, with no jsf backend –  Aug 12 '15 at 10:31
  • @BalusC thanks Balus! Using now it works, but the rendered view doesn't have any JS ora primeface's components rendered. Why?! –  Aug 12 '15 at 10:55

0 Answers0