【问题标题】:Navigation using managed beans [duplicate]使用托管 bean 进行导航 [重复]
【发布时间】:2016-07-06 06:01:33
【问题描述】:

我正在 JSF 2.2 中开发一个简单的项目,但在某些页面之间导航时遇到了一些问题。在项目中,我有一个通用模板,所有视图都是该通用模板的模板客户端。

这是我有问题的观点:

<h:body>

    <ui:composition template="./LayoutGeneral.xhtml">

        <ui:define name="content">
            <p:commandButton value="Registrar Comunidad" action="#{comunidadBean.irRegisterView}"/>
        </ui:define>

    </ui:composition>

</h:body>

在 commandButton 的操作中,我从托管 bean 调用一个方法(Thar 托管 bean 有我调用的其他方法来更改页面,它们工作正常,但这个方法没有):

(托管 Bean)

@ManagedBean
@SessionScoped
public class ComunidadBean {    
    private String idComunidad;
    private String idPresidente;
    private String calle;
    private int numero;
    private int nVecinos;

    @EJB
    private ComunidadDAO ejb;

    public String register(){
        if(ejb.realizaRegistro(this)){
            return "principalView";
        } else{
            FacesMessage fm = new FacesMessage ("No se pudo registrar");
            FacesContext.getCurrentInstance().addMessage("msg", fm);
            return null;
        }
    }

    public String irRegisterView(){
        return "registroCView";
    }

}

所以“注册”方法工作正常,页面发生变化,但“irRegisterView”方法没有导航到“registroCView”页面。

有人知道发生了什么吗?

谢谢!

【问题讨论】:

    标签: jsf jsf-2 navigation managed-bean


    【解决方案1】:

    我不能评论,所以我写这个作为答案。

    • 我看到你的 bean 是SessionScoped。您需要实现 Serializable,因为 SessionScoped bean 会在一段时间后钝化。
    • 你有LayoutGeneral.xhtml 的表格吗?否则,此代码将永远无法运行,因为 commandButton 需要在表单中。
    • 为什么将方法称为属性?在 JSF 2.2 和 EL 2.3 中,您可以像这样调用方法:#{comunidadBean.isRegisterView()}
    • 单击按钮时是否抛出异常?如果有,请粘贴堆栈跟踪。

    【讨论】:

    • 非常感谢!!问题是 commandButton 不在表单内!我不知道它必须是那样的!
    猜你喜欢
    • 2014-10-19
    • 2015-04-23
    • 2013-10-19
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 2012-03-26
    • 2012-05-18
    相关资源
    最近更新 更多