Please I appreciate your help with this issue. I have a autocomplete with an abstract converter. Normally, it works well, except when I use a validator or a f:validator. When I put the validator on the autocomplete, it goes to the generic converter, but in instead of returning the object, it always put the id value in the autocomplete input. Normally it does well this flow, by putting the object and making reference to the attribute of the class in the itemLabel. But only when I put a validator, the behavior is to put the id, making insecure the system by putting a id directly. What could be the problem.
this is the autocomplete code:
Code: Select all
<p:autoComplete id="menuAutoComplete"
dropdown="true"
value="#{menuBean.entity.menu}"
var="menu"
itemLabel="#{menu.name}"
itemValue="#{menu}"
completeMethod="#{menuBean.completeMenu}"
converter="#{menuBean.converter}"
forceSelection="false"
required="#{menuBean.menuNeeded}"
size="100"
validator="menuValidator"
>
<p:ajax event="itemSelect"
listener="#{menuBean.handleSelectMenu}"
update="systemOutputLabel, systemOutputPanel, moduleOutputLabel, moduleOutputPanel"
oncomplete="PF('modulebui').show();PF('systembui').show()"
/>
this is the abstractConverter
Code: Select all
public class GenericConverter implements Converter {
protected EntityService service;
@Autowired
public void setService(EntityService service) {
this.service = service;
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
Long id = Long.parseLong(value);
return service.find(id);
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value instanceof BaseEntity ? ((BaseEntity) value).getId().toString() : "";
}
}
Code: Select all
@Component
@Scope("request")
@FacesValidator("menuValidator")
public class MenuValidator implements Validator {
@Autowired
UsuarioService usuarioService;
@Autowired
MessagesController messagesController;
@Override
public void validate(FacesContext fc, UIComponent uic, Object value) throws ValidatorException {
if(value == null){
return;
}
Menu menu = (Menu) value;
if(menu.getNombre().equals("Menu1") ){
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "test error",
"test error");
throw new ValidatorException(msg);
}
}
}
thanks in advance,
Darío