I have two selectonemenu in Primefaces. How do I force one or both to be selected?

1

a query please, I have two selectOneMenu of primefaces in a view, what I need to do is that the user if I do not select either of them select at least one.

I set required = true but this makes me have to select both selectOneMenu and the idea is that if the user wants he can only select one. There should be an if or something to condition them but I do not know how to do it

Thanks in advance

    
asked by Didier Orjuela 03.09.2016 в 01:51
source

2 answers

1

One solution would be to add a validation in the submit of the form, example a button type = submit.

primefaces button example:

   <p:commandButton id="buscarPreciosSinFiltro2"  value="enviar" actionListener = "#{nombreBean.metodoValidar}" update = "id del los elementos que quieres refrescar"/>

In the bean method you retrieve the value attributes of the selectOneMenu or whatever, and if there is not at least one reported, it displays a message on the same page instead of continuing to browse.

to show the message so that from the BB:

 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Warning!", "Selecciona una al menos bribón."));
    
answered by 05.09.2016 в 17:45
0

I have implemented something like this but between two autocomplete. The main idea is that when you select one, the other does null and that condition is what I put in the required of each. In my case I have persona and proveedor and must be selected or one or the other. Each autocomplete has the following, person and provider respectively:

// Persona
required="#{usuariosControl.usuarioSeleccionado.idProveedor eq null}"

// Proveedor
required="#{usuariosControl.usuarioSeleccionado.idPersona eq null}"

I have two ajax events that are called when you select each one that return null to the other. In addition to a update for the other. That's how I resolved it.

Greetings.

    
answered by 12.10.2016 в 22:38