I have a form in JSF in which I ask to select an option of p:selectOneMenu
that lists meeting names String
but I want to save the object as such mapped: Meeting.
I made the FacesCOnverter
needed to bring me the value of the database and I checked that it performs well but at the time of clicking send in the form does not perform the action of bean
contained in the button p:commandButton
.
<h:form>
<p:messages autoUpdate="true" globalOnly="true"/>
<br /><br />
<table>
<tr>
<td width="150px">Seleccione Reunion: </td>
<td>
<p:selectOneMenu id="nombreEvento" panelStyle="width: 1080px" value="#{registrarDelegadoReunion.reunionSelected}"
converter="reunionConverter" converterMessage="Fallo la conversion de reunion">
<f:selectItems value="#{registrarDelegadoReunion.lisReuniones}" var="reunion1" itemLabel="#{reunion1.nombre}"
itemValue="#{reunion1}" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td width="150px">
<p:commandButton value="Registrar" action="#{registrarDelegadoReunion.registrarDelegadoReunion()}" />
</td>
<td></td>
</tr>
</table>
</h:form>
and this is the bean
of registrarDelegadoReunion
and method registrarDelegadoReunion()
:
@ManagedBean(name = "registrarDelegadoReunion")
//@Named(value= "registrarDelegadoReunion")
@SessionScoped
@Stateless
public class registrarDelegadoReunion implements Serializable
{
private Reunion reunionSelected;
public String registrarDelegadoReunion()
{
//Session sesion=HibernateUtil.getSessionFactory().openSession();
//Transaction transaccion=sesion.beginTransaction();
String urlDestino="msgError";
System.out.println("Entro en registrarDelegadoReunion");
return urlDestino;
}
You are supposed to take the form and do not mind re-sending me to the page called msgError
------------- I added this so that you can guide me:
Hello everyone ... I have verified and the problem results in the converter (I do not know why maybe someone can explain to me) ::: when I do the search in the database to bring the pojo (object of the database called meeting) it is not possible to completely abstract it, maybe because it has references to another table or object called entity that is organizing the meeting. I show you the pojo Reunion:
@Entity
@Table(name="reunion"
,schema="ufps"
)
public class Reunion implements java.io.Serializable {
@Id
@Column(name="id_reunion", unique=true, nullable=false)
public short getIdReunion() {
return this.idReunion;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id_entidad")
public Entidad getEntidad() {
return this.entidad;
}
}
and this my FacesConverter:
@FacesConverter("reunionConverter")
public class ReunionConverter implements Converter
{
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String value)
{
Reunion pe=null;
Session sesion=HibernateUtil.getSessionFactory().openSession();
Transaction transaccion=sesion.beginTransaction();
//Vector<String> vec = new Vector<String>();
if(value != null && value.trim().length() > 0)
{
try
{
String consulta="select s from Reunion s where s.idReunion="+value;
// +value;
System.out.println("consulta: "+consulta);
pe= (Reunion) sesion.createQuery(consulta).uniqueResult();
if(pe==null)
{System.out.println("pe es nulo en Reunionconverter: ");}
else
{System.out.println("Valor de PE en Reunionconverter: "+pe.getNombre());}
} catch(NumberFormatException e)
{
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
}
catch(Exception e)
{
System.out.println("Error en la consulta::: "+e.getMessage());
}
finally
{
transaccion.commit();
System.out.println("cerro sesion en reunionCOnverter");
sesion.close();
}
}
return pe;
//return null;
}
public String getAsString(FacesContext fc, UIComponent uic, Object object)
{
if(object != null)
{
//SubseriePK op=(SubseriePK) object;
System.out.println("Objeto en converter reunion: "+ String.valueOf(((Reunion) object).getIdReunion()));
return String.valueOf(((Reunion) object).getIdReunion());
}
}
As I told you, it does not allow me to abstract the meeting object, since I do the test with other tables (objects) that do not have foraneas and there if he brings them to me and executes the bean.