DataModel and Row Unavailable
ssc_ch Jun 28, 2007 3:44 AMI have some problems in using the datamodel.
I have two Tables on my page and i add entries from one table to the 2nd, which works fine.
After adding i should have the possibility to remove entries again from the 2nd table, which works, but only with the first entry..
If i alway delete the first entry until the table is empty this is again no problem, but if i like to delete an entry in the middle or at the end, I get an exception saying the row is unavailable..
My Bean:
@Stateful
@Scope(ScopeType.CONVERSATION)
@Name("caseAction")
public class CaseAction implements ICase,Serializable{
 @PersistenceContext
 private EntityManager em;
 @In
 private User authUser;
 @Logger
 private Log log;
 @In
 private FacesMessages facesMessages;
 private PersistentFacesState state;
 @In(create=true)
 @Out(required=false)
 private Patient patient;
 @Out(value="selectedMedCase",required=false)
 MedCase mcase;
 @In(create=true)
 @Out(required=false)
 private CaseType caseType;
 @DataModel(value="professionals")
 private List<HealthProfessional> professionals;
 @DataModelSelection(value="professionals")
 @Out(required=false)
 private HealthProfessional selectedProfessional;
 @DataModel(value="searchProfessionals")
 private List<HealthProfessional> searchProfessionals;
 @DataModelSelection(value="searchProfessionals")
 @Out(required=false)
 private HealthProfessional selectedSearchedProfessionals;
 private String description;
 public CaseAction(){
 }
 @Begin(join=true)
 @Factory("searchProfessionals")
 public void initSearchProfessionals(){
 searchProfessionals = em.createQuery("FROM HealthProfessional hp " +
 "order by hp.lastname").getResultList();
 professionals = new ArrayList<HealthProfessional>();
 }
 @End
 public String create(){
 log.info("create")
 return "/protected/prof/profMyCases.seam";
 }
 public void deleteProf(){
 professionals.remove(selectedProfessional);
 state = PersistentFacesState.getInstance();
 log.info("delete Health Professional");
 }
 public void addProf(){
 if(!professionals.contains(selectedSearchedProfessionals)){
 professionals.add(selectedSearchedProfessionals);
 }
 log.info("added Health Professional: #{selectedSearchedProfessionals}");
 }
 public void patientChanged(ValueChangeEvent event){
 log.info("patient change event");
 }
 public List<Patient> getMyPatients(){
 HealthProfessional prof = (HealthProfessional)authUser;
 List<Patient> patients;
 patients = em.createNamedQuery("findAllPatientOfProfessional")
 .setParameter("prof", prof).getResultList();
 return patients;
 }
 public List<CaseType> getCaseTypes(){
 List<CaseType> types;
 types = em.createNamedQuery("findAllCaseTypes").getResultList();
 return types;
 }
 public String getDescription(){
 return description;
 }
 public void setDescription(String description){
 this.description = description;
 }
 @Destroy @Remove
 public void destroy(){
 }
}
My website:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:jsp="http://java.sun.com/JSP/Page"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:ice="http://www.icesoft.com/icefaces/component"
 xmlns:s="http://jboss.com/products/seam/taglib"
 template="../../layout/template.jsp">
 <ui:define name="content">
 <ice:panelAccordion expanded="true" styleClass="accordion">
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.title']}" />
 </f:facet>
 <ice:form id="form">
 <ice:panelGrid columns="3">
 <ice:outputText value="#{messages['profNewCase.patient']}" />
 <ice:outputText value="#{messages['profNewCase.description']}" />
 <ice:outputText value="#{messages['profNewCase.type']}" />
 <h:selectOneMenu id="patientListbox" required="true"
 value="#{patient}" >
 <s:selectItems value="#{caseAction.myPatients}" var="patient"
 label="#{patient.firstname} #{patient.lastname}"
 noSelectionLabel="#{messages['profNewCase.noSelection']}"/>
 <s:convertEntity />
 </h:selectOneMenu>
 <ice:inputText required="true" value="#{caseAction.description}" />
 <h:selectOneMenu id="typeListbox" required="true"
 value="#{caseType}">
 <s:selectItems value="#{caseAction.caseTypes}" var="caseType"
 label="#{caseType.type}"
 noSelectionLabel="#{messages['profNewCase.noSelection']}"/>
 <s:convertEntity />
 </h:selectOneMenu>
 </ice:panelGrid>
 <ice:outputText value="#{messages['profNewCase.notAdded']}"
 rendered="#{professionals != null and professionals.rowCount==0}"/>
 <ice:dataTable var="prof" value="#{professionals}"
 sortColumn="#{list.sort}" sortAscending="#{list.ascending}"
 scrollable="#{table.scrollable}"
 scrollHeight="#{table.scrollableHeight}"
 columnWidths="150px,150px,150px,150px"
 rendered="#{professionals.rowCount>0}">
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.responsibleProf']}" />
 </f:facet>
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.firstname']}" />
 </f:facet>
 <ice:outputText value="#{prof.firstname}" />
 </ice:column>
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.lastname']}" />
 </f:facet>
 <ice:outputText value="#{prof.lastname}" />
 </ice:column>
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.state']}" />
 </f:facet>
 <ice:outputText value="#{prof.state}" />
 </ice:column>
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.edit']}" />
 </f:facet>
 <s:link value="[delete]" action="#{caseAction.deleteProf}" />
 </ice:column>
 </ice:dataTable>
 <br />
 <ice:commandButton type="submit" value="#{messages['profNewCase.create']}"
 action="#{caseAction.create}" />
 </ice:form>
 <ice:form id="searchForm">
 <ice:panelAccordion expanded="true" styleClass="accordion">
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.search']}" />
 </f:facet>
 <ice:outputText value="No Health Professionals Found"
 rendered="#{searchProfessionals != null and searchProfessionals.rowCount==0}"/>
 <ice:dataTable var="sProfs" value="#{searchProfessionals}"
 sortColumn="#{list.sort}" sortAscending="#{list.ascending}"
 scrollable="#{table.scrollable}"
 scrollHeight="#{table.scrollableHeight}"
 columnWidths="150px,150px,150px,150px"
 rendered="#{searchProfessionals.rowCount>0}">
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.firstname']}" />
 </f:facet>
 <ice:outputText value="#{sProfs.firstname}" />
 </ice:column>
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.lastname']}" />
 </f:facet>
 <ice:outputText value="#{sProfs.lastname}" />
 </ice:column>
 <ice:column>
 <f:facet name="header">
 <ice:outputText value="#{messages['profNewCase.edit']}" />
 </f:facet>
 <s:link value="[add]" action="#{caseAction.addProf}" />
 </ice:column>
 </ice:dataTable>
 </ice:panelAccordion>
 </ice:form>
 </ice:panelAccordion>
 </ui:define>
</ui:composition>
 
     
     
    