Jsf验证错误(由h:message显示)同时更新Model,为什么? [英] Jsf validation error (shown by h:message) while updating Model, why?

查看:112
本文介绍了Jsf验证错误(由h:message显示)同时更新Model,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List.xhtml:

List.xhtml:

 <h:selectOneMenu value="#{produtosController.selected.codigo}">
    <f:selectItems value="#{produtosController.itemsAvailableSelectOne}"/>
 </h:selectOneMenu>
 <h:commandButton action="#{produtosController.createByCodigos}" value="Buscar" />  

控制器类方法:

 public String createByCodigos(){
    items = new ListDataModel(ejbFacade.findByCodigos(current.getCodigo()));
    updateCurrentItem();
    return "List";
}  

门面类方法:

 public List<Produtos> findByCodigos(Integer codigo){
    Query q = em.createNamedQuery("Produtos.findByCodigo");
    q.setParameter("codigo", codigo);
    return q.getResultList();
}

Bean类查询:

 @NamedQuery(name = "Produtos.findByCodigo", query = "SELECT p FROM Produtos p WHERE p.codigo = :codigo")

 @Column(name = "codigo")
 private Integer codigo;


推荐答案

这是一个:

    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof Produtos) {
            Produtos o = (Produtos) object;
            return getStringKey(o.getId());
        } else {
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: "+ProdutosController.class.getName());
        }

这是另一个:

    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        ProdutosController controller = (ProdutosController)facesContext.getApplication().getELResolver().
                getValue(facesContext.getELContext(), null, "produtosController");
        return controller.ejbFacade.find(getKey(value));
    }

这是velue丢失的:getValue(facesContext.getELContext()null ,produtosController);?

Is this where the velue gets lost: getValue(facesContext.getELContext() null, "produtosController");?

这篇关于Jsf验证错误(由h:message显示)同时更新Model,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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