在我的jsf网络应用程序中,我使用了primefaces 5.0并且在点击提交按钮(p:commandbutton
)时遇到了麻烦。事实是,请求没有到达控制器,根据我的p:消息条件,我在页面顶部只有一条验证消息。
填写' selectonemenu'
的代码 public List<SelectItem> getTipoProfissionalItems() throws Exception {
final List<TipoProfissional> listaTipoProf = TipoProfissionalService.listarTodos();
List<SelectItem> tipoProfissionalSelectItens = new ArrayList<>(listaTipoProf.size() + 1);
tipoProfissionalSelectItens.add(new SelectItem(null, "-- Selecione --"));
for (TipoProfissional tipoProf : listaTipoProf) {
tipoProfissionalSelectItens.add(new SelectItem(tipoProf.getId(), tipoProf.getDescricao()));
}
return tipoProfissionalSelectItens;
}
xhtml呈现p:selectOneMenu
:
<p:outputLabel value="Tipo de profissional" for="tipoProf" />
<p:selectOneMenu id="tipoProf" converter="tipoProfissionalConverter" value="#{profissionalMB.tipoProfissional}">
<f:selectItems value="#{profissionalMB.tipoProfissionalItems}" />
</p:selectOneMenu>
我认为问题在于组件在请求时的行为方式,如ajax,立即标记或任何其他。
p:commandButton
代码:
<p:commandButton value="Gravar"
action="#{profissionalMB.gravar}"
update="@form"
title="#{msg.textoBotaoGravarProfissional}" />
类型&#39; TipoProfissional&#39;:
的转换器 @Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
if (string == null || string.length() == 0) {
return null;
}
TipoProfissional tipoProfissional = null;
try {
tipoProfissional = TipoProfissionalService.localizar( Short.parseShort(string) );
} catch (Exception e) {
// todo
}
return tipoProfissional;
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
if (o == null || ("" + o).length() == 0) {
return null;
}
return o.toString();
}
注册&#39; preValidate&#39;事件,我看到了:
public void validateTipoProf(ComponentSystemEvent event) {
UIComponent components = event.getComponent();
UISelectOne selectOne = (UISelectOne) components.findComponent("tipoProf");
logger.info(selectOne.getValue()); // => empty string
logger.info(selectOne.getSubmittedValue()); // => the correct type value
}
似乎没有实施“等于”的问题。方法,除了等于&#39;等等的事实。方法已经收到了PK值,而不是本类中描述的类型。会吗?
在&#39;验证器&#39;专门为组件创建的,选择了OneMenu&#39;填写正确。
数据库表中保留了相同的序列。我还能检查什么?