9 Replies Latest reply on Nov 30, 2007 2:28 AM by Mohammad Dashti

    ajax and EntityHome (Conversation) bug?!

    dudududu Novice

      I set my EntityHome to be in Conversation scope.
      I am accesing it from the same page via ajax support and then via ajac command ,
      in the first ajax call I setId(1)
      in the second ajax call I am trying to update() but it seem that the id = null
      is that a bug? or is there anything I don't do right?
      should I change my EntityHome to be a statefull or conversation is enough?

        • 1. Re: ajax and EntityHome (Conversation) bug?!
          fhh Expert

          Do you pass the conversationId in your ajax call?

          Regards

          Felix

          • 2. Re: ajax and EntityHome (Conversation) bug?!
            dudududu Novice

            yes I do..

            my xhtml:

            <?xml version="1.0" encoding="Windows-1255" ?>
            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
            
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:s="http://jboss.com/products/seam/taglib"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
             template="/layout/template.xhtml">
            
             <ui:define name="body">
            
             <h:messages globalOnly="true" styleClass="message" id="globalMessages" />
             <!-- FILTER -->
             <a4j:form id="customerSearch" styleClass="edit" dir="rtl">
             <rich:simpleTogglePanel label=" ????? ?????? "
             switchType="client" style="direction:rtl">
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">??</ui:define>
             <h:inputText id="name" value="#{customerList.customer.name}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?? ???</ui:define>
             <h:inputText id="shortName"
             value="#{customerList.customer.shortName}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?????</ui:define>
             <h:inputText id="address" value="#{customerList.customer.address}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?????2</ui:define>
             <h:inputText id="address2"
             value="#{customerList.customer.address2}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?????</ui:define>
             <h:inputText id="phoneNumber"
             value="#{customerList.customer.phoneNumber}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">????? 2</ui:define>
             <h:inputText id="phoneNumber2"
             value="#{customerList.customer.phoneNumber2}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">???</ui:define>
             <h:inputText id="fax" value="#{customerList.customer.fax}" />
             </s:decorate>
            
             </rich:simpleTogglePanel>
            
            
            
            <div class="actionButtons">
             <a4j:commandButton
             reRender="customerTable" value="?????" /></div>
            
            
             <rich:panel id="customerTable">
             <f:facet name="header">??????</f:facet>
             <div class="results" id="customerList">
            
             <a4j:region >
             <rich:dataTable
             onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
             onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
             id="customerListTable" var="customer" value="#{customerList.customers}"
             rowKey="#{customer.id}" rowKeyVar="custId" >
            
            
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="??? #{customerList.order=='id asc' ? messages.down : ( customerList.order=='id desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='id asc' ? 'id desc' : 'id asc'}" />
             </s:link>
             </f:facet>
             #{customer.id}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="?? #{customerList.order=='name asc' ? messages.down : ( customerList.order=='name desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='name asc' ? 'name desc' : 'name asc'}" />
             </s:link>
             </f:facet>
             #{customer.name}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="?? ??? #{customerList.order=='shortName asc' ? messages.down : ( customerList.order=='shortName desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='shortName asc' ? 'shortName desc' : 'shortName asc'}" />
             </s:link>
             </f:facet>
             #{customer.shortName}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="????? #{customerList.order=='address asc' ? messages.down : ( customerList.order=='address desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='address asc' ? 'address desc' : 'address asc'}" />
             </s:link>
             </f:facet>
             #{customer.address}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="?????2 #{customerList.order=='address2 asc' ? messages.down : ( customerList.order=='address2 desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='address2 asc' ? 'address2 desc' : 'address2 asc'}" />
             </s:link>
             </f:facet>
             #{customer.address2}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="????? #{customerList.order=='phoneNumber asc' ? messages.down : ( customerList.order=='phoneNumber desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='phoneNumber asc' ? 'phoneNumber desc' : 'phoneNumber asc'}" />
             </s:link>
             </f:facet>
             #{customer.phoneNumber}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="?????2 #{customerList.order=='phoneNumber2 asc' ? messages.down : ( customerList.order=='phoneNumber2 desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='phoneNumber2 asc' ? 'phoneNumber2 desc' : 'phoneNumber2 asc'}" />
             </s:link>
             </f:facet>
             #{customer.phoneNumber2}
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <s:link styleClass="columnHeader"
             value="??? #{customerList.order=='fax asc' ? messages.down : ( customerList.order=='fax desc' ? messages.up : '' )}">
             <f:param name="order"
             value="#{customerList.order=='fax asc' ? 'fax desc' : 'fax asc'}" />
             </s:link>
             </f:facet>
             #{customer.fax}
             </rich:column>
             <rich:column>
             <f:facet name="header">action</f:facet>
             <s:link view="/#{empty from ? 'Customer' : from}.xhtml"
             value="Select" id="customer">
             <f:param name="customerId" value="#{customer.id}" />
             </s:link>
             </rich:column>
             <a4j:support event="onRowClick"
             oncomplete="javascript:Richfaces.showModalPanel('custForm:panel')"
             reRender="panel" data="#{rowKey}"
             actionListener="#{customerHome.selectCustomerFromTable}">
             <s:conversationId/>
             <a4j:actionparam name="cust" id="cust" assignTo="#{customerHome.id}" value="#{customer.id}"/>
            
             </a4j:support>
            
             </rich:dataTable>
             </a4j:region>
             </div>
             </rich:panel></a4j:form>
             <!-- POPUP -->
             <a4j:region id="popupregion">
             <a4j:form id="custForm">
             <rich:modalPanel id="panel" width="400" height="400">
             <f:facet name="header">
             <h:outputText value="???? ????" />
             </f:facet>
            
             <h:panelGrid columns="1">
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">id</ui:define>
             <h:inputText id="custId" value="#{customerHome.instance.id}" />
             </s:decorate>
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">??</ui:define>
             <h:inputText id="name" value="#{customerHome.instance.name}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?? ???</ui:define>
             <h:inputText id="shortName"
             value="#{customerHome.instance.shortName}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?????</ui:define>
             <h:inputText id="address" value="#{customerHome.instance.address}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?????2</ui:define>
             <h:inputText id="address2"
             value="#{customerHome.instance.address2}" />
             </s:decorate>
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">?????</ui:define>
             <h:inputText id="phoneNumber"
             value="#{customerHome.instance.phoneNumber}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">????? 2</ui:define>
             <h:inputText id="phoneNumber2"
             value="#{customerHome.instance.phoneNumber2}" />
             </s:decorate>
            
             <s:decorate template="/layout/display.xhtml">
             <ui:define name="label">???</ui:define>
             <h:inputText id="fax" value="#{customerHome.instance.fax}" />
             </s:decorate>
             <a4j:commandButton id="updateCustomerButton" reRender="customerListTable" action="#{customerHome.update}" ajaxSingle="true" value="????"
             oncomplete="javascript:Richfaces.hideModalPanel('custForm:panel')" ><s:conversationId/></a4j:commandButton>
             <h:commandButton onclick="javascript:Richfaces.hideModalPanel('custForm:panel')" value="????"></h:commandButton>
             </h:panelGrid>
            
             </rich:modalPanel>
             </a4j:form>
             </a4j:region>
            
            
             </ui:define>
            </ui:composition>
            

            here is my EntityHome
            package com.metalogic.superfine.entity;
            
            import java.util.ArrayList;
            import java.util.List;
            
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.faces.event.ActionEvent;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.framework.EntityHome;
            @Scope(ScopeType.CONVERSATION)
            @Name("customerHome")
            @Stateful
            public class CustomerHome extends EntityHome<Customer> implements LocaLCustomerHome{
             @Override
             public Customer getInstance() {
             // TODO Auto-generated method stub
             return super.getInstance();
             }
             @Override
             public void setId(Object arg0) {
             // TODO Auto-generated method stub
             super.setId(arg0);
             }
             @Remove
             public void destroy() {}
             public void setCustomerId(String id) {
             setId(new Integer(id));
             }
            
             public Integer getCustomerId() {
             return (Integer) getId();
             }
            
             @Override
             protected Customer createInstance() {
             Customer customer = new Customer();
             return customer;
             }
            
             public void wire() {
             }
            
             public boolean isWired() {
             return true;
             }
            
             public Customer getDefinedInstance() {
             return isIdDefined() ? getInstance() : null;
             }
            
             public List<CustomerAccounting> getCustomerAccountings() {
             return getInstance() == null
             ? null
             : new ArrayList<CustomerAccounting>(getInstance()
             .getCustomerAccountings());
             }
             public List<Invoice> getInvoices() {
             return getInstance() == null ? null : new ArrayList<Invoice>(
             getInstance().getInvoices());
             }
             public List<CustomerConnection> getCustomerConnections() {
             return getInstance() == null
             ? null
             : new ArrayList<CustomerConnection>(getInstance()
             .getCustomerConnections());
             }
             public void selectCustomerFromTable(ActionEvent event){
             setId(new Integer(getId().toString()));
             }
            
             @Override
             public String update() {
             System.out.println("UPDATE");
             return super.update();
             }
             @Override
             public void create() {
             // TODO Auto-generated method stub
             super.create();
             }
            
            }
            


            • 3. Re: ajax and EntityHome (Conversation) bug?!
              dudududu Novice

              what i am trying to do here is:
              a table of customers
              when someone clikc on spesfic row(customer) then I show a pop-up
              with the customer details
              and then I would like to change the details and press update.

              when I add the following code to pages.xml:

              <page view-id="/customer/index.xhtml" action="#{conversation.begin}">
               </page>

              my pop up is showing empty fields :(
              \here is my xhtml all over again , shorter..
              <?xml version="1.0" encoding="Windows-1255" ?>
              <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
              
              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
               xmlns:s="http://jboss.com/products/seam/taglib"
               xmlns:ui="http://java.sun.com/jsf/facelets"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
               xmlns:rich="http://richfaces.ajax4jsf.org/rich"
               template="/layout/template.xhtml">
              
               <ui:define name="body">
              
               <h:messages globalOnly="true" styleClass="message" id="globalMessages" />
               <!-- FILTER -->
               <a4j:form id="customerSearch" styleClass="edit" dir="rtl">
               <rich:simpleTogglePanel label=" ????? ?????? "
               switchType="client" style="direction:rtl">
              
               <s:decorate template="/layout/display.xhtml">
               <ui:define name="label">name</ui:define>
               <h:inputText id="name" value="#{customerList.customer.name}" />
               </s:decorate>
              
              
               </rich:simpleTogglePanel>
              
              
              
              <div class="actionButtons">
               <a4j:commandButton
               reRender="customerTable" value="filter" /></div>
              
              
               <rich:panel id="customerTable">
               <f:facet name="header">table</f:facet>
               <div class="results" id="customerList">
              
               <a4j:region >
               <rich:dataTable
               onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
               onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
               id="customerListTable" var="customer" value="#{customerList.customers}"
               rowKey="#{customer.id}" rowKeyVar="custId" >
              
              
               <rich:column>
               <f:facet name="header">
               <s:link styleClass="columnHeader"
               value="id #{customerList.order=='id asc' ? messages.down : ( customerList.order=='id desc' ? messages.up : '' )}">
               <f:param name="order"
               value="#{customerList.order=='id asc' ? 'id desc' : 'id asc'}" />
               </s:link>
               </f:facet>
               #{customer.id}
               </rich:column>
               <rich:column>
               <f:facet name="header">
               <s:link styleClass="columnHeader"
               value="name #{customerList.order=='name asc' ? messages.down : ( customerList.order=='name desc' ? messages.up : '' )}">
               <f:param name="order"
               value="#{customerList.order=='name asc' ? 'name desc' : 'name asc'}" />
               </s:link>
               </f:facet>
               #{customer.name}
               </rich:column>
              
               <a4j:support event="onRowClick"
               oncomplete="javascript:Richfaces.showModalPanel('custForm:panel')"
               reRender="panel" data="#{rowKey}"
               actionListener="#{customerHome.selectCustomerFromTable}">
               <s:conversationId/>
               <a4j:actionparam name="cust" id="cust" assignTo="#{customerHome.id}" value="#{customer.id}"/>
               </a4j:support>
              
               </rich:dataTable>
               </a4j:region>
               </div>
               </rich:panel></a4j:form>
               <!-- POPUP -->
               <a4j:region id="popupregion">
               <a4j:form id="custForm">
               <rich:modalPanel id="panel" width="400" height="400">
               <f:facet name="header">
               <h:outputText value="edit customer" />
               </f:facet>
              
               <h:panelGrid columns="1">
               <s:decorate template="/layout/display.xhtml">
               <ui:define name="label">id</ui:define>
               <h:inputText id="custId" value="#{customerHome.instance.id}" />
               </s:decorate>
               <s:decorate template="/layout/display.xhtml">
               <ui:define name="label">name</ui:define>
               <h:inputText id="name" value="#{customerHome.instance.name}" />
               </s:decorate>
              
              
               <a4j:commandButton id="updateCustomerButton" reRender="customerListTable" action="#{customerHome.update}" ajaxSingle="true" value="UPDATE"
               oncomplete="javascript:Richfaces.hideModalPanel('custForm:panel')" >
               <s:conversationId/>
               </a4j:commandButton>
               <h:commandButton onclick="javascript:Richfaces.hideModalPanel('custForm:panel')" value="close"></h:commandButton>
               </h:panelGrid>
              
               </rich:modalPanel>
               </a4j:form>
               </a4j:region>
              
              
               </ui:define>
              </ui:composition>
              


              • 4. Re: ajax and EntityHome (Conversation) bug?!
                dudududu Novice

                ok , I solved one thing
                I added @Begin(join=true) annotation to the first method I'm calling
                but now i've different problem
                the popup doesn't send the new data I enter in the input boxes to the bean ...is it because of the conversation?...what's going on..

                • 5. Re: ajax and EntityHome (Conversation) bug?!
                  Mohammad Dashti Newbie

                  I've the same problem, did you solved your problem?

                  • 6. Re: ajax and EntityHome (Conversation) bug?!
                    Damian Harvey Master

                    You are trying to reRender the modal but you need to reRender a panel inside the modal instead.

                    Cheers,

                    Damian.

                    • 7. Re: ajax and EntityHome (Conversation) bug?!
                      Mohammad Dashti Newbie

                      I've solved some problems, but a crazy thing comes up.

                      I have these 3 files:

                      VisitsEdit.xhtml

                      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      
                      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:s="http://jboss.com/products/seam/taglib"
                       xmlns:ui="http://java.sun.com/jsf/facelets"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:a="http://richfaces.org/a4j"
                       xmlns:rich="http://richfaces.org/rich"
                       template="layout/template.xhtml">
                      
                      <ui:define name="body">
                      
                       <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
                      
                       <h:form id="visit" styleClass="edit">
                      
                       <rich:panel>
                       <f:facet name="header">#{messages['Edit']} #{messages['Visit']}</f:facet>
                      
                       <s:decorate id="visitDateTimeDecoration" template="layout/edit.xhtml">
                       <ui:define name="label">#{messages['visitDateTime']}</ui:define>
                       <h:inputText id="visitDateTime"
                       size="16"
                       required="false"
                       value="#{visitHome.instance.visitDateTime}">
                       <s:convertDateTime type="both" dateStyle="short" />
                       <a:support event="onblur" reRender="visitDateTimeDecoration" bypassUpdates="true"/>
                       </h:inputText>
                       </s:decorate>
                      
                       <s:decorate id="visitDescriptionDecoration" template="layout/edit.xhtml">
                       <ui:define name="label">#{messages['visitDescription']}</ui:define>
                       <h:inputTextarea id="visitDescription"
                       cols="80"
                       rows="3"
                       value="#{visitHome.instance.visitDescription}"/>
                       </s:decorate>
                      
                       <s:decorate id="visitKindDecoration" template="layout/edit.xhtml">
                       <ui:define name="label">#{messages['visitKind']}</ui:define>
                       <h:inputTextarea id="visitKind"
                       cols="80"
                       rows="3"
                       value="#{visitHome.instance.visitKind}"/>
                       </s:decorate>
                      
                       <s:decorate id="placeStateDecoration" template="layout/edit.xhtml">
                       <ui:define name="label">#{messages['placeState']}</ui:define>
                       <h:inputTextarea id="placeState"
                       cols="80"
                       rows="3"
                       value="#{visitHome.instance.placeState}"/>
                       </s:decorate>
                      
                       <s:decorate id="wardenDecoration" template="layout/display.xhtml">
                       <ui:define name="label">#{messages['warden']}</ui:define>
                       <h:selectOneMenu value="#{visitHome.instance.warden}">
                       <s:selectItems value="#{visitHome.wardensList}" var="ward" label="#{ward.user.firstName} #{ward.user.lastName}" noSelectionLabel="#{messages['PleaseSelectOne']}"></s:selectItems>
                       <s:convertEntity />
                       </h:selectOneMenu>
                       </s:decorate>
                      
                       <div style="clear:both">
                       <span class="required">*</span>
                       #{messages['requiredfields']}
                       </div>
                      
                       </rich:panel>
                      
                       <div class="actionButtons">
                      
                       <h:commandButton id="save"
                       value="#{messages['Save']}"
                       action="#{visitHome.persist}"
                       disabled="#{!visitHome.wired}"
                       rendered="#{!visitHome.managed}"/>
                      
                       <h:commandButton id="update"
                       value="#{messages['Save']}"
                       action="#{visitHome.update}"
                       rendered="#{visitHome.managed}"/>
                      
                       <h:commandButton id="delete"
                       value="#{messages['Delete']}"
                       action="#{visitHome.remove}"
                       rendered="#{visitHome.managed}"/>
                      
                       <s:button id="done"
                       value="#{messages['Done']}"
                       propagation="end"
                       view="/Visit.xhtml"
                       rendered="#{visitHome.managed}"/>
                      
                       <s:button id="cancel"
                       value="#{messages['Cancel']}"
                       propagation="end"
                       view="/#{empty visitFrom ? 'VisitList' : visitFrom}.xhtml"
                       rendered="#{!visitHome.managed}"/>
                      
                       </div>
                       </h:form>
                      
                      <a:form id="formInstanceSelection">
                       <rich:tabPanel switchType="ajax" id="visitTabPanel">
                      
                       <rich:tab label="#{messages['formInstances']}">
                       <div class="association" id="formInstancesChildren">
                      
                       <h:outputText value="#{messages['NoFormInstances']}"
                       rendered="#{empty visitHome.formInstances}"/>
                      
                       <rich:dataTable value="#{visitHome.formInstances}"
                       var="formInstance"
                       rendered="#{not empty visitHome.formInstances}"
                       rowClasses="rvgRowOne,rvgRowTwo"
                       id="formInstancesTable"
                       onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
                       onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                       rowKey="#{formInstance.id}" rowKeyVar="fiId">
                       <rich:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       <h:outputText value="#{formInstance.formInstanceId}"/>
                       </rich:column>
                       <rich:column>
                       <f:facet name="header">#{messages['creationDate']}</f:facet>
                       <h:outputText value="#{formInstance.creationDate}"/>
                       </rich:column>
                       <rich:column>
                       <f:facet name="header">#{messages['action']}</f:facet>
                       <s:link view="/FormInstance.xhtml"
                       id="selectformInstance"
                       value="#{messages['Select']}"
                       propagation="none">
                       <f:param name="formInstanceFormInstanceId"
                       value="#{formInstance.formInstanceId}"/>
                       <f:param name="formInstanceFrom" value="Visit"/>
                       </s:link>
                      
                       </rich:column>
                       <a:support event="onRowClick" oncomplete="javascript:Richfaces.showModalPanel('mpFormInstance');"
                       reRender="insideMP" data="#{rowKey}"
                       actionListener="#{formInstanceHome.selectFormInstanceFromTable}">
                       <s:conversationId/>
                       <a:actionparam name="fi" id="fi" assignTo="#{formInstanceHome.id}" value="#{formInstance.formInstanceId}"/>
                      
                       </a:support>
                       </rich:dataTable>
                      
                       </div>
                      
                       <f:subview rendered="#{visitHome.managed}" id="formInstances">
                       <div class="actionButtons">
                      
                       <s:button onclick="Richfaces.showModalPanel('mpFormInstance');return false;" value="baba in jadide !"></s:button>
                      
                       <s:button id="addformInstance"
                       value="#{messages['AddFormInstance']}"
                       view="/FormInstanceEdit.xhtml"
                       propagation="none">
                       <f:param name="visitVisitId"
                       value="#{visitHome.instance.visitId}"/>
                       <f:param name="formInstanceFrom" value="Visit"/>
                       </s:button>
                       </div>
                       </f:subview>
                       </rich:tab>
                      
                      
                       <rich:tab label="workers">
                       <div class="association" id="workersChildren">
                      
                       <h:outputText value="#{messages['NoWorkers']}"
                       rendered="#{empty visitHome.workers}"/>
                      
                       <rich:dataTable value="#{visitHome.workers}"
                       var="worker"
                       rendered="#{not empty visitHome.workers}"
                       rowClasses="rvgRowOne,rvgRowTwo"
                       id="workersTable">
                       <h:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       <h:outputText value="#{worker.workerId}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['action']}</f:facet>
                       <s:link view="/Worker.xhtml"
                       id="selectworker"
                       value="#{messages['Select']}"
                       propagation="none">
                       <f:param name="workerWorkerId"
                       value="#{worker.workerId}"/>
                       <f:param name="workerFrom" value="Visit"/>
                       </s:link>
                       </h:column>
                       </rich:dataTable>
                      
                       </div>
                      
                       <f:subview rendered="#{visitHome.managed}" id="workers">
                       <div class="actionButtons">
                       <s:button id="addworker"
                       value="#{messages['AddWorker']}"
                       view="/WorkerEdit.xhtml"
                       propagation="none">
                       <f:param name="visitVisitId"
                       value="#{visitHome.instance.visitId}"/>
                       <f:param name="workerFrom" value="Visit"/>
                       </s:button>
                       </div>
                       </f:subview>
                       </rich:tab>
                      
                       <rich:tab label="warden">
                       <div class="association" id="wardenParent">
                      
                       <h:outputText value="#{messages['NoWarden']}"
                       rendered="#{visitHome.instance.warden == null}"/>
                      
                       <rich:dataTable var="warden"
                       value="#{visitHome.instance.warden}"
                       rendered="#{visitHome.instance.warden != null}"
                       rowClasses="rvgRowOne,rvgRowTwo"
                       id="wardenTable">
                       <h:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       #{warden.wardenId}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['userHumanId']}</f:facet>
                       #{warden.user.humanId}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['action']}</f:facet>
                       <s:link view="/Warden.xhtml"
                       id="viewwarden"
                       value="#{messages['View']}"
                       propagation="none">
                       <f:param name="wardenWardenId"
                       value="#{warden.wardenId}"/>
                       </s:link>
                       </h:column>
                       </rich:dataTable>
                      
                       <div class="actionButtons">
                       <s:button value="#{messages['SelectWarden']}"
                       view="/WardenList.xhtml">
                       <f:param name="from" value="VisitEdit"/>
                       </s:button>
                       </div>
                      
                       </div>
                       </rich:tab>
                      
                       <rich:tab label="paravndehPlace">
                       <div class="association" id="paravndehPlaceParent">
                      
                       <h:outputText value="#{messages['NoParavndehPlace']}"
                       rendered="#{visitHome.instance.paravndehPlace == null}"/>
                      
                       <rich:dataTable var="paravndehPlace"
                       value="#{visitHome.instance.paravndehPlace}"
                       rendered="#{visitHome.instance.paravndehPlace != null}"
                       rowClasses="rvgRowOne,rvgRowTwo"
                       id="paravndehPlaceTable">
                       <h:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       #{paravndehPlace.parvandehId}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['ParvandehKind']}</f:facet>
                       #{paravndehPlace.parvandehKind.parvandehKindId}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       #{paravndehPlace.radif}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['placeAddress']}</f:facet>
                       #{paravndehPlace.placeAddress}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['placeTelephone']}</f:facet>
                       #{paravndehPlace.placeTelephone}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['isNamayandegi']}</f:facet>
                       #{paravndehPlace.isNamayandegi}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['mahalhayeTahiyeType']}</f:facet>
                       #{paravndehPlace.mahalhayeTahiyeType}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['mahalhayeTahiyeName']}</f:facet>
                       #{paravndehPlace.mahalhayeTahiyeName}
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['action']}</f:facet>
                       <s:link view="/ParavndehPlace.xhtml"
                       id="viewparavndehPlace"
                       value="#{messages['View']}"
                       propagation="none">
                       <f:param name="paravndehPlaceParvandehId"
                       value="#{paravndehPlace.parvandehId}"/>
                       </s:link>
                       </h:column>
                       </rich:dataTable>
                      
                       <div class="actionButtons">
                       <s:button value="#{messages['SelectParavndehPlace']}"
                       view="/ParavndehPlaceList.xhtml">
                       <f:param name="from" value="VisitEdit"/>
                       </s:button>
                       </div>
                      
                       </div>
                       </rich:tab>
                      
                       <rich:tab label="destroyeds">
                       <div class="association" id="destroyedsChildren">
                      
                       <h:outputText value="#{messages['NoDestroyeds']}"
                       rendered="#{empty visitHome.destroyeds}"/>
                      
                       <rich:dataTable value="#{visitHome.destroyeds}"
                       var="destroyed"
                       rendered="#{not empty visitHome.destroyeds}"
                       rowClasses="rvgRowOne,rvgRowTwo"
                       id="destroyedsTable">
                       <h:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       <h:outputText value="#{destroyed.destroyedId}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['placeName']}</f:facet>
                       <h:outputText value="#{destroyed.placeName}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['destroyedDateTime']}</f:facet>
                       <h:outputText value="#{destroyed.destroyedDateTime}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['kindOfJens']}</f:facet>
                       <h:outputText value="#{destroyed.kindOfJens}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['tedad']}</f:facet>
                       <h:outputText value="#{destroyed.tedad}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['vaznVahed']}</f:facet>
                       <h:outputText value="#{destroyed.vaznVahed}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['vaznKol']}</f:facet>
                       <h:outputText value="#{destroyed.vaznKol}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['destroyedCause']}</f:facet>
                       <h:outputText value="#{destroyed.destroyedCause}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['action']}</f:facet>
                       <s:link view="/Destroyed.xhtml"
                       id="selectdestroyed"
                       value="#{messages['Select']}"
                       propagation="none">
                       <f:param name="destroyedDestroyedId"
                       value="#{destroyed.destroyedId}"/>
                       <f:param name="destroyedFrom" value="Visit"/>
                       </s:link>
                       </h:column>
                       </rich:dataTable>
                      
                       </div>
                      
                       <f:subview rendered="#{visitHome.managed}" id="destroyeds">
                       <div class="actionButtons">
                       <s:button id="adddestroyed"
                       value="#{messages['AddDestroyed']}"
                       view="/DestroyedEdit.xhtml"
                       propagation="none">
                       <f:param name="visitVisitId"
                       value="#{visitHome.instance.visitId}"/>
                       <f:param name="destroyedFrom" value="Visit"/>
                       </s:button>
                       </div>
                       </f:subview>
                       </rich:tab>
                      
                      </rich:tabPanel>
                      </a:form>
                      <a:region id="popupregion">
                      
                       <rich:modalPanel id="mpFormInstance" minHeight="400" minWidth="400" height="500" width="1000" top="15" zindex="2000" >
                      
                       <f:facet name="header">
                      
                       <h:outputText value="#{messages['formModalPanelTitle']} " />
                      
                       </f:facet>
                      
                       <f:facet name="controls">
                      
                       <h:graphicImage value="img/close.png" style="cursor:pointer" onclick="Richfaces.hideModalPanel('mpFormInstance')" />
                      
                       </f:facet>
                      
                      
                      
                       <a:form id="MPform">
                       <s:div id="insideMP">
                      
                       <rich:panel>
                       <f:facet name="header">#{messages['Edit']} #{messages['FormInstance']} #{messages['FormInstance']} #{formInstanceHome.instance.formStructure.formName != null ? formInstanceHome.instance.formStructure.formName : ''}</f:facet>
                       <s:decorate id="fidDec" template="layout/display.xhtml">
                       <ui:define name="label">fid</ui:define>
                       <f:verbatim>#{formInstanceHome.instance.formInstanceId}</f:verbatim>
                       </s:decorate>
                       <s:decorate id="creationDateDecoration" template="layout/edit.xhtml">
                       <ui:define name="label">#{messages['creationDate']}</ui:define>
                       <rich:calendar id="creationDate"
                       value="#{formInstanceHome.instance.creationDate}" pattern="MM/dd/yyyy" event="onblur" reRender="creationDateDecoration" bypassUpdates="true"/>
                       </s:decorate>
                      
                       <s:decorate id="formStructuresDecoration" template="layout/display.xhtml">
                       <ui:define name="label">#{messages['FormStructures']}</ui:define>
                       <h:selectOneMenu value="#{formInstanceHome.selectedFormStructure}" >
                       <f:selectItems value="#{formInstanceHome.formStructures}" ></f:selectItems>
                       <s:convertEntity />
                       </h:selectOneMenu>
                       </s:decorate>
                      
                       <div style="clear:both">
                       <span class="required">*</span>
                       #{messages['requiredfields']}
                       </div>
                      
                       </rich:panel>
                      
                       <div class="actionButtons">
                      
                       <a:commandButton id="updateFormInstanceButton"
                       reRender="formInstancesTable"
                       action="#{formInstanceHome.update}"
                       value="felan in kar mikone?"
                       oncomplete="javascript:Richfaces.hideModalPanel('mpFormInstance')" >
                       <s:conversationId/>
                       </a:commandButton>
                       <a:commandButton onclick="javascript:Richfaces.hideModalPanel('mpFormInstance')" value="beband"></a:commandButton>
                      
                       <a:commandButton id="save"
                       value="#{messages['Save']}"
                       action="#{formInstanceHome.persist}"
                       disabled="#{!formInstanceHome.wired}"
                       rendered="#{!formInstanceHome.managed}"
                       reRender="insideMP">
                       </a:commandButton>
                      
                      
                       <a:commandButton id="update"
                       value="#{messages['Save']}"
                       action="#{formInstanceHome.update}"
                       rendered="#{formInstanceHome.managed}"
                       reRender="fieldValuesTable">
                       </a:commandButton>
                      
                       <h:commandButton id="delete"
                       value="#{messages['Delete']}"
                       onclick="#{messages['com.behdasht.CONFIRM_DELETE']}"
                       action="#{formInstanceHome.remove}"
                       rendered="#{formInstanceHome.managed}"/>
                      
                       <s:button id="done"
                       value="#{messages['Done']}"
                       propagation="end"
                       view="/VisitEdit.xhtml"
                       rendered="#{formInstanceHome.managed}">
                       <f:param name="visitVisitId" value="#{visit.visitId}" />
                       </s:button>
                      
                       <s:button id="cancel"
                       value="#{messages['Cancel']}"
                       propagation="end"
                       view="/#{empty formInstanceFrom ? 'FormInstanceList' : formInstanceFrom}.xhtml"
                       rendered="#{!formInstanceHome.managed}"/>
                      
                       </div>
                      
                      
                       <div class="association" id="fieldValuesChildren">
                      
                       <rich:dataTable value="#{formInstanceHome.fieldValues}"
                       var="fieldValue"
                       rendered="#{not empty formInstanceHome.fieldValues}"
                       rowClasses="rvgRowOne,rvgRowTwo"
                      
                       id="fieldValuesTable">
                       <h:column>
                       <f:facet name="header">#{messages['radif']}</f:facet>
                       <h:outputText value="#{fieldValue.fieldValueId}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{messages['Desription']}</f:facet>
                       <h:outputText value="#{fieldValue.field.fieldDescription}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">#{(formInstanceHome.instance.formStructure.formType == 1 or formInstanceHome.instance.formStructure.formType == 2) ? messages['Extra'] : (formInstanceHome.instance.formStructure.formType == 3 ? messages['Result'] : messages['Value'])}</f:facet>
                       <s:span rendered="#{fieldValue.field.fieldType == 2}">
                       <s:decorate id="strValDecoration" template="layout/editformgen.xhtml">
                       <h:inputTextarea id="strVal" value="#{fieldValue.stringValue}" style=" width :100%;">
                       <a:support event="onblur" reRender="strValDecoration" bypassUpdates="true"/>
                       </h:inputTextarea>
                       </s:decorate>
                       </s:span>
                       <s:span rendered="#{(fieldValue.field.fieldType == 1 and formInstanceHome.instance.formStructure.formType != 1)}">
                       <s:decorate id="chkValDecoration" template="layout/editformgen.xhtml">
                       <h:selectBooleanCheckbox id="chkVal" value="#{fieldValue.booleanValue}">
                       <a:support event="onblur" reRender="chkValDecoration" bypassUpdates="true"/>
                       </h:selectBooleanCheckbox>
                       </s:decorate>
                       </s:span>
                       <s:span rendered="#{fieldValue.field.fieldType == 3}">
                       <s:decorate id="intValDecoration" template="layout/editformgen.xhtml">
                       <h:inputText id="intVal" value="#{fieldValue.integerValue}">
                       <a:support event="onblur" reRender="intValDecoration" bypassUpdates="true"/>
                       </h:inputText>
                       </s:decorate>
                       </s:span>
                       <s:span rendered="#{fieldValue.field.fieldType == 4}">
                       <s:decorate id="dblValDecoration" template="layout/editformgen.xhtml">
                       <h:inputText id="dblVal" value="#{fieldValue.doubleValue}">
                       <a:support event="onblur" reRender="dblValDecoration" bypassUpdates="true"/>
                       </h:inputText>
                       </s:decorate>
                       </s:span>
                       <s:span rendered="#{fieldValue.field.fieldType == 5}">
                       <s:decorate id="dateValDecoration" template="layout/editformgen.xhtml">
                       <rich:calendar id="dateVal" value="#{fieldValue.dateValue}" pattern="MM/dd/yyyy" event="onblur" reRender="creationDateDecoration" bypassUpdates="true">
                       <a:support event="onblur" reRender="dateValDecoration" bypassUpdates="true"/>
                       </rich:calendar>
                       </s:decorate>
                       </s:span>
                       <s:span rendered="#{fieldValue.field.fieldType == 6}">
                       <h:selectOneMenu value="#{fieldValue.trippleStateValue}" >
                       <f:selectItems value="#{formInstanceHome.threeSatet}" ></f:selectItems>
                       </h:selectOneMenu>
                      
                       </s:span>
                      
                      
                       </h:column>
                       <h:column rendered="#{formInstanceHome.instance.formStructure.formType == 1}">
                       <f:facet name="header">#{messages['Value']}</f:facet>
                       <s:span>
                       <s:decorate id="checkValDecoration" template="layout/display.xhtml">
                       <h:selectBooleanCheckbox id="checkVal" value="#{fieldValue.booleanValue}">
                       <a:support event="onblur" reRender="checkValDecoration" bypassUpdates="true"/>
                       </h:selectBooleanCheckbox>
                       </s:decorate>
                       </s:span>
                       </h:column>
                      
                       <h:column rendered="#{formInstanceHome.instance.formStructure.formType == 2}">
                       <f:facet name="header">#{messages['Value']}</f:facet>
                       <s:span>
                       <s:decorate id="emtiyazValDecoration" template="layout/editformgen.xhtml">
                       <h:inputText id="emtiyazVal" value="#{fieldValue.emtiyaz}">
                       <a:support event="onblur" reRender="emtiyazValDecoration" bypassUpdates="true"/>
                       </h:inputText>
                       </s:decorate>
                       </s:span>
                       </h:column>
                      
                       </rich:dataTable>
                       </div>
                      
                      
                      
                      
                       </s:div>
                       </a:form>
                       </rich:modalPanel>
                       </a:region>
                      
                       <a:log></a:log>
                       </ui:define>
                      
                      </ui:composition>
                      



                      VisitsHome.java

                      package com.behdasht.eb;
                      
                      import java.util.ArrayList;
                      import java.util.List;
                      import org.jboss.seam.annotations.In;
                      import org.jboss.seam.annotations.Name;
                      import org.jboss.seam.framework.EntityHome;
                      import org.richfaces.component.html.HtmlModalPanel;
                      
                      @Name("visitHome")
                      public class VisitHome extends EntityHome<Visit> {
                      
                       @In(create = true)
                       WardenHome wardenHome;
                       @In(create = true)
                       ParavndehPlaceHome paravndehPlaceHome;
                      
                      
                       public String rerender(){
                       return null;
                       }
                      
                       public void setVisitVisitId(Long id) {
                       setId(id);
                       }
                      
                       public Long getVisitVisitId() {
                       return (Long) getId();
                       }
                      
                       @Override
                       protected Visit createInstance() {
                       Visit visit = new Visit();
                       return visit;
                       }
                      
                       public void wire() {
                       Warden warden = wardenHome.getDefinedInstance();
                       if (warden != null) {
                       getInstance().setWarden(warden);
                       }
                       ParavndehPlace paravndehPlace = paravndehPlaceHome.getDefinedInstance();
                       if (paravndehPlace != null) {
                       getInstance().setParavndehPlace(paravndehPlace);
                       }
                       }
                      
                       public boolean isWired() {
                       return true;
                       }
                      
                       public Visit getDefinedInstance() {
                       return isIdDefined() ? getInstance() : null;
                       }
                      
                       public List<Destroyed> getDestroyeds() {
                       return getInstance() == null ? null : new ArrayList<Destroyed>(
                       getInstance().getDestroyeds());
                       }
                       public List<FormInstance> getFormInstances() {
                       return getInstance() == null ? null : getInstance().getFormInstances();
                       }
                       public List<Worker> getWorkers() {
                       return getInstance() == null ? null : new ArrayList<Worker>(
                       getInstance().getWorkers());
                       }
                      
                      // public HtmlModalPanel getFormeInstanceMP(){
                      // HtmlModalPanel fisPanel = new HtmlModalPanel();
                      // fisPanel.setId("mpFormInstance");
                      // fisPanel.setMinHeight(500);
                      // fisPanel.setMinWidth(500);
                      // fisPanel.setWidth(1000);
                      // fisPanel.setHeight(500);
                      // fisPanel.setTop("15");
                      // fisPanel.setZindex(2000);
                      //
                      //
                      // return fisPanel;
                      // }
                      
                      
                       public List<Warden> getWardensList() {
                       return (List<Warden>)getEntityManager().createQuery("from Warden").getResultList();
                       }
                      
                      
                      }
                      
                      
                      



                      and

                      FormInstanceHome.java

                      package com.behdasht.eb;
                      // Generated Nov 2, 2007 11:54:46 AM by Hibernate Tools 3.2.0.b9
                      
                      import java.util.Date;
                      import java.util.ArrayList;
                      import java.util.List;
                      import javax.persistence.CascadeType;
                      import javax.persistence.Column;
                      import javax.persistence.Entity;
                      import javax.persistence.FetchType;
                      import javax.persistence.GeneratedValue;
                      import javax.persistence.Id;
                      import javax.persistence.JoinColumn;
                      import javax.persistence.ManyToOne;
                      import javax.persistence.OneToMany;
                      import javax.persistence.Table;
                      import javax.persistence.Temporal;
                      import javax.persistence.TemporalType;
                      import org.hibernate.validator.NotNull;
                      
                      /**
                       * FormInstance generated by hbm2java
                       */
                      @Entity
                      @Table(name = "form_instance", catalog = "behdasht")
                      public class FormInstance implements java.io.Serializable {
                      
                       /**
                       *
                       */
                       private static final long serialVersionUID = -5080864813582715025L;
                      
                       private long formInstanceId;
                       private Visit visit;
                       private FormStructure formStructure;
                       private Date creationDate;
                       private List<FieldValue> fieldValues = new ArrayList<FieldValue>(0);
                      
                       public FormInstance() {
                       }
                      
                       public FormInstance(long formInstanceId) {
                       this.formInstanceId = formInstanceId;
                       }
                       public FormInstance(long formInstanceId, Visit visit,
                       FormStructure formStructure, Date creationDate,
                       List<FieldValue> fieldValues) {
                       this.formInstanceId = formInstanceId;
                       this.visit = visit;
                       this.formStructure = formStructure;
                       this.creationDate = creationDate;
                       this.fieldValues = fieldValues;
                       }
                      
                       @Id
                       @Column(name = "Form_instance_id", unique = true, nullable = false)
                       @NotNull
                       @GeneratedValue
                       public long getFormInstanceId() {
                       return this.formInstanceId;
                       }
                      
                       public void setFormInstanceId(long formInstanceId) {
                       this.formInstanceId = formInstanceId;
                       }
                       @ManyToOne(fetch = FetchType.LAZY)
                       @JoinColumn(name = "visitVisit_id")
                       public Visit getVisit() {
                       return this.visit;
                       }
                      
                       public void setVisit(Visit visit) {
                       this.visit = visit;
                       }
                       @ManyToOne(fetch = FetchType.LAZY)
                       @JoinColumn(name = "form_structureForm_structure_id")
                       public FormStructure getFormStructure() {
                       return this.formStructure;
                       }
                      
                       public void setFormStructure(FormStructure formStructure) {
                       this.formStructure = formStructure;
                       }
                       @Temporal(TemporalType.DATE)
                       @Column(name = "Creation_date", length = 0)
                       public Date getCreationDate() {
                       return this.creationDate;
                       }
                      
                       public void setCreationDate(Date creationDate) {
                       this.creationDate = creationDate;
                       }
                       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "formInstance")
                       public List<FieldValue> getFieldValues() {
                       return this.fieldValues;
                       }
                      
                       public void setFieldValues(List<FieldValue> fieldValues) {
                       this.fieldValues = fieldValues;
                       }
                      
                      }
                      
                      



                      but , something workd wrong! it doen't work properly!

                      I'll appreciate you're help! please help me!

                      • 8. Re: ajax and EntityHome (Conversation) bug?!
                        Mohammad Dashti Newbie

                        excuse me, the las file in the previous post was FormInstance.java.


                        FormInstanceHome.java:

                        package com.behdasht.eb;
                        
                        import java.util.ArrayList;
                        import java.util.List;
                        
                        import javax.faces.event.ActionEvent;
                        import javax.faces.model.SelectItem;
                        
                        import org.jboss.seam.annotations.Begin;
                        import org.jboss.seam.annotations.In;
                        import org.jboss.seam.annotations.Logger;
                        import org.jboss.seam.annotations.Name;
                        import org.jboss.seam.core.ResourceBundle;
                        import org.jboss.seam.framework.EntityHome;
                        import org.jboss.seam.log.Log;
                        
                        @Name("formInstanceHome")
                        public class FormInstanceHome extends EntityHome<FormInstance> {
                        
                         @In(create = true)
                         VisitHome visitHome;
                         @In(create = true)
                         FormStructureHome formStructureHome;
                        
                         public void setFormInstanceFormInstanceId(Long id) {
                         setId(id);
                         }
                        
                         public Long getFormInstanceFormInstanceId() {
                         return (Long) getId();
                         }
                        
                         @Override
                         protected FormInstance createInstance() {
                         FormInstance formInstance = new FormInstance();
                         return formInstance;
                         }
                        
                         public void wire() {
                        
                         Visit visit = visitHome.getDefinedInstance();
                         if (visit != null) {
                         getInstance().setVisit(visit);
                         }
                         FormStructure formStructure = formStructureHome.getDefinedInstance();
                         if (formStructure != null) {
                         getInstance().setFormStructure(formStructure);
                         }
                         }
                        
                         public boolean isWired() {
                         return true;
                         }
                        
                         public FormInstance getDefinedInstance() {
                         return isIdDefined() ? getInstance() : null;
                         }
                        
                         public List<FieldValue> getFieldValues() {
                         return getInstance() == null ? null : getInstance().getFieldValues();
                         }
                        
                        
                        
                        
                        
                         @Logger
                         Log log;
                         private int fieldNum;
                         private List<SelectItem> formStructures;
                         private List<SelectItem> threeState;
                         FormStructure selectedFormStructure;
                         @Override
                         public String persist(){
                         super.persist();
                         List<FieldValue> fieldValues;
                         if (selectedFormStructure != null ) {
                         getDefinedInstance().setFormStructure(selectedFormStructure);
                         fieldValues = new ArrayList<FieldValue>();
                         FieldValue fv;
                         for(Field f : getDefinedInstance().getFormStructure().getFields()){
                         fv = new FieldValue();
                         fv.setField(f);
                         fv.setFormInstance(getDefinedInstance());
                         fieldValues.add(fv);
                         getEntityManager().persist(fv.getFormInstance());
                         }
                         getDefinedInstance().setFieldValues(fieldValues);
                         super.update();
                         }
                        
                         return "persisted";
                         }
                        
                         //@Begin(join=true)
                         public void selectFormInstanceFromTable(ActionEvent event){
                         FormInstance fi = (FormInstance)getEntityManager().createQuery("select fi from FormInstance fi where fi.formInstanceId=:fid").setParameter("fid", new Long((String)getId())).getSingleResult();
                         setInstance(fi);
                         setId(fi.getFormInstanceId());
                         }
                        
                         @Override
                         public String update() {
                         if(getInstance() == null)
                         log.info("baba aslan nulleeeeeeeeeeeeeeeeeeee !!");
                         log.info("oomad inja tooye update!!\n" + "fi.getID()=" + getInstance().getFormInstanceId());
                         //getEntityManager().refresh(getInstance());
                         super.update();
                         List<FieldValue> fieldValues;
                         if (selectedFormStructure != null && selectedFormStructure != getInstance().getFormStructure()) {
                         for(FieldValue fv : getDefinedInstance().getFieldValues()){
                         fv.setFormInstance(null);
                         fv.setField(null);
                         getEntityManager().remove(fv);
                         }
                         getInstance().setFieldValues(null);
                         getInstance().setFormStructure(selectedFormStructure);
                        
                         fieldValues = new ArrayList<FieldValue>();
                         FieldValue fv;
                         for(Field f : getInstance().getFormStructure().getFields()){
                         fv = new FieldValue();
                         fv.setField(f);
                         fv.setFormInstance(getDefinedInstance());
                         fieldValues.add(fv);
                         getEntityManager().persist(fv.getFormInstance());
                         }
                         getInstance().setFieldValues(fieldValues);
                         super.update();
                         }
                        
                         return "updated";
                         }
                        
                         public int getFieldNum() {
                         fieldNum++;
                         return fieldNum;
                         }
                        
                         public List<SelectItem> getFormStructures(){
                         formStructures = new ArrayList<SelectItem>();
                         SelectItem si;
                         List<FormStructure> list = (List<FormStructure>)getEntityManager().createQuery("from FormStructure").getResultList();
                         for(FormStructure fs : list){
                         si = new SelectItem();
                         si.setLabel(fs.getFormName());
                         si.setValue(fs);
                         formStructures.add(si);
                         }
                         return formStructures;
                         }
                        
                         public List<SelectItem> getThreeSatet() {
                         if (threeState == null){
                        
                         threeState = new ArrayList<SelectItem>();
                        
                        
                         threeState.add(new SelectItem(0, ResourceBundle.instance().getString("Unknown")));
                         threeState.add(new SelectItem(1, ResourceBundle.instance().getString("Yes")));
                         threeState.add(new SelectItem(-1, ResourceBundle.instance().getString("No")));
                        
                         }
                        
                         return threeState;
                         }
                        
                         public void newInstance() {
                         FormInstance instance = createInstance();
                         super.setInstance(instance);
                         }
                        
                         public FormStructure getSelectedFormStructure() {
                         selectedFormStructure = getInstance().getFormStructure();
                         return selectedFormStructure;
                         }
                        
                         public void setSelectedFormStructure(FormStructure selectedFormStructure) {
                         this.selectedFormStructure = selectedFormStructure;
                         }
                        
                        }