【发布时间】:2011-04-18 06:27:10
【问题描述】:
(ps:对不起我的英语)
我的应用程序中有一个文本字段,对于这个文本字段,我有一个 a4j:support 应该适用于 onchange 事件!所以我有相同的包含和更新表格。 用户用代码填充文本字段,在我的 bean 中,我有一个方法可以搜索等效组合框(如果该值存在),然后将其设置为我的 bean 对象,这适用于包含但不适用于更新!我不知道这可能是什么。我会发布代码。
我的 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;
}
这是填充 listItemsTipoVinculo 的方法
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 中,因此当页面启动时,我已将其填充。当用户将代码放在文本字段中时,它应该调用 findbykey 方法,但他们没有!当我的对象“prestador”被填充时,就在我的更新屏幕中。
【问题讨论】: