最高效的 JSF 1.2 java 导航

发布于 2024-11-07 09:45:43 字数 1941 浏览 4 评论 0原文

我的index.xhtml JSF 首页上有一个下拉菜单。关联的代码/commandButton 如下所示:

    <h:selectOneMenu id="nodes" value="#{MyBacking.chosenNode}">
    <f:selectItems value="#{MyBacking.nodes}" />
</h:selectOneMenu>

<a4j:commandButton value="Retrieve" styleClass="ctrlBtn"
    id="retrieveBtn" style="margin-bottom: 2px;"
    onclick="#{rich:component('nodeLoadWait')}.show()"   # modal
    action="#{MyBacking.redirect}"
    image="/img/btnRetrieve26.png" />

action 之前设置为“hello”,在我的 faces-context.xml 中:

<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>hello</from-outcome>
        <to-view-id>/nodeMgmt.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

action设置为“hello”,单击retrieve按钮工作正常,因为faces将处理导航,并且MyBacking.setChosenNode方法将分配所有必要的数据,以便内容nodeMgmt.xhtml 将显示为完全填充。

但是,如果由用户单击 retrieve 引起的初始活动超时,即使 Bean 检测到超时,网页也会挂起,并且我想将用户重定向到“超时” ' 页。

为了处理返回超时消息的支持 bean(在应用程序“内部”时已经存在错误检测),我想而不是使用 faces-context.xml 文件,我会内部处理一下。

我发现 FacesContext.getCurrentInstance().getExternalContext().redirect 但 JSF 1.2 javadoc 没有此功能。也许是因为它没有特色?它会重定向,但这很令人困惑。为什么没有关于此方法的文档?

尽管如此,它还是将我重定向到该页面,但在渲染时不考虑 Bean 在初始请求期间实例化的数据。该 bean 当前位于请求范围内。 bean 中的相关代码是

    try {
        FacesContext.getCurrentInstance().getExternalContext().redirect("nodeMgmt.jsf");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Is using a backend java call the best way to do this kind of redirection? 如果没有,最好使用faces-context.xml吗?如果是这样,怎么办? 当我们在这里时,任何人都可以指导我找到有关 FacesContext.getCurrentInstance().getExternalContext() 用法的良好阅读资源,其中有关于如何使用数据进行简单导航的不错的示例,因为我找不到一个。

干杯

I've got a dropdown on my index.xhtml JSF front page. The associated code/commandButton looks like this:

    <h:selectOneMenu id="nodes" value="#{MyBacking.chosenNode}">
    <f:selectItems value="#{MyBacking.nodes}" />
</h:selectOneMenu>

<a4j:commandButton value="Retrieve" styleClass="ctrlBtn"
    id="retrieveBtn" style="margin-bottom: 2px;"
    onclick="#{rich:component('nodeLoadWait')}.show()"   # modal
    action="#{MyBacking.redirect}"
    image="/img/btnRetrieve26.png" />

action was set to 'hello' previously, and in my faces-context.xml:

<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>hello</from-outcome>
        <to-view-id>/nodeMgmt.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

When action was set to 'hello', clicking the retrieve button worked OK in that faces would handle the nav and MyBacking.setChosenNode method would assign all the necessary data, so that the content of nodeMgmt.xhtml would be displayed fully populated.

However, if the initial activity caused by the user clicking retrieve times out, the web page would hang even though the bean detects the time out, and I'd like to redirect the user to a 'timed out' page.

In order to handle the backing bean returning a timedout message (the error detection for which is already present when 'inside' the app), I thought rather than using the faces-context.xml file, I would handle it internally.

I found FacesContext.getCurrentInstance().getExternalContext().redirect but the JSF 1.2 javadoc does not feature this. Perhaps it's because it's not featured? It redirects though which is confusing. Why no documentation on this method?

Nonetheless, it redirects me to the page, but renders without taking into account the data instantiated by the bean during the initial request. The bean is in request scope currently. The relevant code in the bean is

    try {
        FacesContext.getCurrentInstance().getExternalContext().redirect("nodeMgmt.jsf");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Is using a backend java call the best way to do this kind of redirection?
If not, is it best to use faces-context.xml? If so, how?
While we're here - can anyone direct me to a good reading resource for FacesContext.getCurrentInstance().getExternalContext() usage which has decent examples about how to do simple navigation with data cos I'm having trouble locating one.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城挽邺 2024-11-14 09:45:43

我发现 FacesContext.getCurrentInstance().getExternalContext().redirect 但 JSF 1.2 javadoc 没有此功能。也许是因为它没有特色?它会重定向,但这很令人困惑。为什么没有关于此方法的文档?

当然有。

可能您读错了 javadoc。也许是 FacesContext 之一?


尽管如此,它还是将我重定向到该页面,但在渲染时没有考虑 Bean 在初始请求期间实例化的数据。该 bean 当前位于请求范围内。

重定向指示浏览器触发全新的 HTTP 请求。因此,旧请求中的所有请求作用域 bean 将被丢弃并在新请求中重新初始化。如果您想保留请求,则可以使用转发(JSF 默认使用转发),但这不适用于 ajax 发起的请求,因为无论如何它都会停留在同一页面。只有带有重定向的响应才会强制 Ajax 使用 JavaScript 更改窗口位置。

如果您想在新请求中保留某些参数,则必须将它们作为请求参数传递。例如

externalContext.redirect("nodeMgmt.jsf?foo=bar");

,将它们设置为 bean 中的托管属性。

I found FacesContext.getCurrentInstance().getExternalContext().redirect but the JSF 1.2 javadoc does not feature this. Perhaps it's because it's not featured? It redirects though which is confusing. Why no documentation on this method?

There certainly is.

Probably you was reading the wrong javadoc. The one of FacesContext perhaps?


Nonetheless, it redirects me to the page, but renders without taking into account the data instantiated by the bean during the initial request. The bean is in request scope currently.

A redirect instructs the browser to fire a brand new HTTP request. So all request scoped beans from the old request will be garbaged and reinitialized in the new request. If you'd like to retain the request, you'd like to use a forward instead (which JSF by default uses), but this isn't going to work on ajax-initiated requests as it will stick to the same page anyway. Only a response with a redirect will force Ajax to change the window location using JavaScript.

If you want to retain some parameters in the new request, you'd have to pass them as request parameters. E.g.

externalContext.redirect("nodeMgmt.jsf?foo=bar");

and set them as managed property in the bean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文