aspose file tools*
The moose likes JSF and the fly likes jsf selectOneMenu & hibernate relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf selectOneMenu & hibernate relationship" Watch "jsf selectOneMenu & hibernate relationship" New topic
Author

jsf selectOneMenu & hibernate relationship

Laurent Baye
Greenhorn

Joined: Oct 30, 2006
Posts: 3
Hi all,

I've encountered a little pb here:


=========================================================
saisie.jsp
======================================================================
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>


<f:loadBundle basename="popup" var="msgPopup" />
<f:loadBundle basename="jourSaisie" var="msgsJourSaisie" />
<f:loadBundle basename="command" var="msgsCommand" />


<f:subview id="subviewSaisieTableId">
<t:saveState value="#{semaineSaisieBean.semaineSaisieId}" />
<h:inputHidden id="inputSemaineId"
value="#{semaineSaisieBean.semaineSaisie.semaineSaisieId}" />

<t:newspaperTable var="rowJour"
value="#{semaineSaisieBean.semaineSaisie.jourSaisieList}" id="El_pais"
newspaperColumns="7">
<h:column>
<h:panelGrid columns="1" styleClass="table_m" headerClass="th_m"
rowClasses="td_m">
<f:facet name="header">
<h:panelGroup>
<hutputText value="#{rowJour.nomDuJour}" />
<hutputText value="#{rowJour.dateSaisie}">
<f:convertDateTime dateStyle="long" type="date" timeZone="GMT+2:00" />
</hutputText>
</h:panelGroup>
</f:facet>

<h:panelGrid columns="1">
<f:facet name="header">
<hutputText value="#{msgsJourSaisie.morning}" />
</f:facet>
<h:selectOneMenu value="#{rowJour.tempsTravailAM.projetId}"
styleClass="form" immediate="true">
<f:selectItem itemLabel="Absence" itemValue="absence" />
<f:selectItems value="#{ressourceSelectMenuMap.projetMap}" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="1">
<f:facet name="header">
<hutputText value="#{msgsJourSaisie.afternoon}" />
</f:facet>
<h:selectOneMenu value="#{rowJour.tempsTravailPM.projetId}"
styleClass="form" immediate="true">
<f:selectItem itemLabel="Absence" itemValue="absence" />
<f:selectItems value="#{ressourceSelectMenuMap.projetMap}" />
</h:selectOneMenu>
</h:panelGrid>
</h:panelGrid>
</h:column>
</t:newspaperTable>

<h:commandButton action="saisie"
actionListener="#{semaineSaisieBean.saveSemaine}"
value="#{msgsCommand.save}" styleClass="form" id="saveSemaine" />

</f:subview>
======================================================================



basically, the aim of this is to save a list of jourSaisie (day entries for a sort of scheduler) with each jourSaisie having a tempsTravailAM/PM (working Time).
So we have the following objects:
SemaineSaisie --> jourSaisie --> tempsTravail --> projetId

We have mapped these in a hibernate(SQL) dB.

We can create a list of these objects but we can't save the tempsTravailId in the table of jourSaisie (many to one relationship), although we can save the semaineSaisieId in jourSaisie (one to many relationship).

We think the problem comes form the fact that we have two types of tempsTravail (distinguished by the type element in the TempsTravail.class)


in case you want to look at our methods :


this is first called when we get to our page (saisie.jsp)
=====================================================================
semaineManager.class
=====================================================================
public void saveAllObjectsFromSemaine(SemaineSaisie semaineSaisie) {



ArrayList jourList = (ArrayList) semaineSaisie.getJourSaisieList();
ListIterator it = jourList.listIterator();

SemaineSaisie semaine = (SemaineSaisie) saveReturnObject(semaineSaisie);

while (it.hasNext ()) {

JourSaisie jour = (JourSaisie) jourList.get(it.nextIndex());

TempsTravail travailAm = jour.getTempsTravailAM();
TempsTravail travailPm = jour.getTempsTravailPM();
travailAm = (TempsTravail) saveReturnObject(travailAm);
travailPm = (TempsTravail) saveReturnObject(travailPm);

jour.setTempsTravailAmId(travailAm.getTempsTravailId());
jour.setTempsTravailPmId(travailPm.getTempsTravailId());
jour.setSemaineSaisieId(semaine.getSemaineSaisieId());
jour.setJourSaisieListIdx(it.nextIndex());

save(jour);

it.next();
}
}
=====================================================================




these are thes methods we call with SemaineSaisieBean.save
!! But the jsf page never actually gets into it , it just reloads...
=====================================================================
SemaineSaisieBean.class
=====================================================================
public void saveSemaine(ActionEvent e) {
System.out.println("START SemaineBean.saveSemaine()");

/*
* semaineSaisie.setEmployeId(1); semaineSaisie.setStatut("ouvert");
* semaineSaisie.setTotalSemaine(1);
*/

semaineManager.save(semaineSaisie);

saveJourList(semaineSaisie.getJourSaisieList(), semaineSaisie
.getSemaineSaisieId());

System.out.println("END ActionBean.saveAppli()");
}


private void saveJourList(List jourList, int id) {

for (int i = 0; i < jourList.size(); i++) {

JourSaisie jour = new JourSaisie();

jour = (JourSaisie) jourList.get(i);

jour.setJourSaisieId(id);

TempsTravail travailAm = jour.getTempsTravailAM();
TempsTravail travailPm = jour.getTempsTravailPM();

if (jour.getTempsTravailAmId() == 0 && jour.getTempsTravailPmId() == 0) {

} else {
travailAm = (TempsTravail) semaineManager
.saveReturnObject(travailAm);
travailPm = (TempsTravail) semaineManager
.saveReturnObject(travailPm);
jour.setTempsTravailAmId(travailAm.getTempsTravailId());
jour.setTempsTravailPmId(travailPm.getTempsTravailId());
}


semaineManager.save(jour);
}
}
=====================================================================




thanks for helping. (and reading ;->)

Laurent &co.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsf selectOneMenu & hibernate relationship