Problems with navigation cases from an embedded JS

2019-08-02 20:19发布

问题:

I'm working on a JSF e-form application. This application needs to be embedded in another web site (one written in JSP). The only way I can embed this is through jQuery at the document ready phase.

I've got all the pages I need embedded and everything is showing up as expected but there is one problem.

On my new form/ edit form web page I have a submit button that updates the form or creates a new one on the server side and then navigates to the successful screen or failure screen when the action is complete.

When this page is embedded, this button still executes the action on the server (awesome!!) but, as expected, redirects the page to the success screen. What I would like to do is stay on the "parent" screen and just replace the embedded page with the success page/failure page.

I think the way I could go about this is to somehow intercept the navigation event from JSF and reload the embedded page from that event. The key here is to not leave the parent page after a submission.

I'm running JSF2.0 (Apache impl.) on Tomcat 6 and the jQuery version is 1.3.

I hope this is clear.. Let me know if you guys need any more info.

Thanks!

回答1:

When this page is embedded, this button still executes the action on the server (awesome!!) but, as expected, redirects the page to the success screen. What I would like to do is stay on the "parent" screen and just replace the embedded page with the success page/failure page.

Just return null or void and conditionally render the content.

Thus so

public void submit() {
    results = processAndGetIt();
}

with e.g.

<h:form>
    ...
    <h:commandButton value="Submit" action="#{bean.submit}">
        <f:ajax execute="@form" render=":results" />
    </h:commandButton>
</h:form>

<h:panelGroup id="results">
    <h:panelGroup rendered="#{not empty bean.results}">
        Results have been retrieved: #{bean.results}.
    </h:panelGroup>
</h:panelGroup>

Note that I added <f:ajax> for better user experience.