现在的位置: 首页 > 综合 > 正文

JSF 跳转至新页面问题

2013年08月03日 ⁄ 综合 ⁄ 共 582字 ⁄ 字号 评论关闭

在Neatbeans中创建JSF文件,在页面中放置一个按钮,作用是点击此按钮,跳转到新的页面而不显示新窗口.
做法是:
双击JSF页面中的按钮,生成JAVA文件中的ACTION()方法.在方法里添加如下代码即可.

  public String button1_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
            if (name.getText().equals("Kage")) {
            try {
                this.getFacesContext().getExternalContext().redirect(
                        "/Action-war/faces/Page2.jsp");
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            name.setText("Name is wrong!");
        }

        return null;
    } 

抱歉!评论已关闭.