JSF - 更改 h:commandButton (2.0) 的操作 [英] JSF - Change the action for a h:commandButton (2.0)

查看:17
本文介绍了JSF - 更改 h:commandButton (2.0) 的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JSF 2.0 的新手.在上一个版本中,我知道如果我想更改有关发送给客户端的内容"的规则,我只需要配置 faces-config.xml.

Im new into JSF 2.0. On the last version i understand that if i want change rules about "what send to the client" i just need to configure the faces-config.xml.

现在,在2.0版本上,如何管理Action?例如,如果我在 index.xhtml 上有这个

Now, on version 2.0, how can manage the Action? For example, if i have this on a index.xhtml

<h:commandButton id="submit" value="submit" action="response" />

我需要调用一个名为 response.html(不是 xhtml)的页面,或者那个页面放在/folder/response.html 中,或者其他什么?怎么办?我知道 JSF 2.0 在这些方面非常灵活(href 链接的概念被打败了).所以我想我可以用其他方法来解决这个问题,对吗?

and i need to call a page called response.html (not xhtml) or that page placed into /folder/response.html, or somethings else? How can do it? I know JSF 2.0 is very flexible about these things (the concept of href links is beaten). So i think i can manage this with other methodologies, right?

推荐答案

action 可以指出两点:

  1. 一个方法表达式 action="#{bean.methodname}",其中的方法如下所示:

  1. A method expression action="#{bean.methodname}" where the method look like this:

@ManagedBean
@RequestScoped
public class Bean {
    public String methodname() {
        // Do some business task here.
        return "response";
    }
}

执行该方法后,该操作将有效地最终包含该方法的返回值,如下所示:action="response".

After executing the method the action will effectively end up containing the return value of the method, like so: action="response".

您还可以使用通常的 Java 方式动态"控制结果:

You can also control the outcome "dynamically" the usual Java way:

public String methodname() {
    if (someCondition) {
        return "somepage";
    } else {
        return "anotherpage";
    }
}

根据条件结果,动作最终会像 action="somepage"action="anotherpage"

Depending on the condition outcome, the action will end up like action="somepage" or action="anotherpage"

与当前 XHTML 页面相同 文件夹中的另一个 XHTML 页面.您只需要指定文件名:action="response".

Another XHTML page in the same folder as the current XHTML page. You just have to specify the filename: action="response".

无论哪种方式,它都会转到由 outcome + ".xhtml" 组成的 XHTML 页面,其中 outcome 是操作值(例如 response.xhtmlsomepage.xhtmlanotherpage.xhtml) 应该与包含 h:commandButton<的 XHTML 文件位于同一文件夹中/代码>.

Either way, it will go to the XHTML page which is composed by outcome + ".xhtml" where outcome is the action value (e.g. response.xhtml, somepage.xhtml or anotherpage.xhtml) which is supposed to be in the same folder as the XHTML file containing the h:commandButton.

您不需要为此在 faces-config.xml 中配置任何内容.以前,在 JSF 1.x 时代,您需要为此定义 .

You don't need to configure anything in faces-config.xml for this. Previously, during JSF 1.x ages you would need to define <navigation-case> for this.

  • We don't need no stinkin' faces-config.xml! - blog by lead Mojarra developer.

这篇关于JSF - 更改 h:commandButton (2.0) 的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆