代码之家  ›  专栏  ›  技术社区  ›  Jorge Campos

事件不在richfaces中调用

  •  1
  • Jorge Campos  · 技术社区  · 15 年前

    (ps:对不起我的英语)

    用户用一个代码填充textfield,在我的bean中我有一个方法来搜索等价的组合框,如果这个值存在,那么将它设置为我bean的对象,这对include很好,但对update不起作用!我不知道这会是什么。我会把密码寄出去。

    我的xhtml页面

    <ui:decorate template="../templates/edit.xhtml">
                        <ui:param name="idComponente" value="codTipoVinculo" />
                        <ui:define name="label">Tipo Vínculo: </ui:define>
                        <h:inputText id="codTipoVinculo"
                            value="#{cadastroPrestadorBean.codTipoVinculo}"
                            size="4" maxlength="1"
                            styleClass="#{validationUtil.invalid('codTipoVinculo', facesContext) ? 'invalido' : ''}"
                            onkeypress="return(soEntraNumero(event,this));" 
                            onmouseout="soArrastaNumero(this);" 
                            onblur="soArrastaNumero(this);">
                            <a4j:support event="onchange" 
                                         action="#{cadastroPrestadorBean.findByKey(cadastroPrestadorBean.prestador.tipoVinculo)}"
                                         ajaxSingle="true"
                                         immediate="true"
                                         focus="codTipoPgtoMatmed"
                                         reRender="nomeTipoVinculo, codTipoVinculo, outputMessagesInForm">
                                <a4j:actionparam noEscape="true"
                                    value="(document.getElementById('formPrestador:codTipoVinculo').value == '' ? '-11111' : document.getElementById('formPrestador:codTipoVinculo').value)"
                                    assignTo="#{cadastroPrestadorBean.codTipoVinculo}" />                                                        
                            </a4j:support>
                        </h:inputText>
                        <rich:comboBox enableManualInput="false"  defaultLabel="Selecione uma opção" id="nomeTipoVinculo"
                            value="#{cadastroPrestadorBean.prestador.tipoVinculo}"
                            converter="simpleIndexConverterTipoVinculo">
                            <f:selectItems
                                value="#{cadastroPrestadorBean.listaTipoVinculo }" />
                            <a4j:support event="onchange" reRender="codTipoVinculo, outputMessagesInForm"
                                ajaxSingle="true" limitToList="true"
                                action="#{cadastroPrestadorBean.findByKey(cadastroPrestadorBean.prestador.tipoVinculo)}" />
                        </rich:comboBox>
                    </ui:decorate>
    

    if (object instanceof TipoVinculo) {
                if ( codTipoVinculo == null || codTipoVinculo == -11111) {
                    prestador.setTipoVinculo(new TipoVinculo());
                    return;
                }
                for (SelectItem element : listItemsTipoVinculo) {
                    if ( ( ((TipoVinculo)element.getValue()).getCodTipoVinculo().intValue() ) == codTipoVinculo ){
                        prestador.setTipoVinculo((TipoVinculo)BeanUtils.cloneBean(element.getValue()));
                        achou = true;
                    }
                }
                if ( !achou ){
                    prestador.setTipoVinculo(new TipoVinculo());
                    addMessageInfo("Tipo Vínculo inválido.");
                }
                achou = false;
            }
    

        public List<SelectItem> getListaTipoVinculo() {
        try {
            if ( listItemsTipoVinculo.size() == 0 ){
                List<TipoVinculo> list = tipoVinculoBusiness.listaTiposVinculos();
                for (TipoVinculo item : list) {
                    listItemsTipoVinculo.add(new SelectItem(item));
                }
            }
        } catch (CommonBusinessException e) {
            addMessageError(e);
        }
        return listItemsTipoVinculo;
    }
    

    组合框以前是在listItemsTipoVinculo中填充的,所以当页面开始时,我会填充它。当用户将代码放在textfield中时,它应该调用findbykey方法,但是他们没有!只是在我的更新屏幕时,我的对象'普雷斯塔多'是填充。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Jorge Campos    15 年前

    我知道发生了什么。。。 这个问题在我的表单中,我正在将我的所有对象设置为新实例,并且只更新数据库中有值的对象。。。

    因此,如果字段为空,我只需签入bean,然后创建一个新实例!

    if ( prestador.getTipoVinculo()==null ){
        prestador.setTipoVinculo(new TipoVinculo());
    }
    

    解决我的问题。。。 无论如何,感谢所有读过这篇文章的人!

    推荐文章