Thanks Kiuma ... I will post but it may complicate since knowledge of the trails framework is essential.

I am at the door of completing this and just trying to get past the OGNL.

Incomplete and currently messy (not cleaned up)

Here is the sources...

Editors.page
   <component id="associationMgt" type="AssociationMgt">
       <binding name="model">model</binding>
       <binding name="value">model[descriptor.name]</binding>
       <binding name="owner">model</binding>
       <binding name="association">model[descriptor.name]</binding>
       <binding name="descriptor">descriptor</binding>
   </component>

   <component id="associationSelect" type="AssociationSelect">
       <binding name="model">model</binding>
       <binding name="value">model[descriptor.name]</binding>
       <binding name="owner">model</binding>
       <binding name="association">model[descriptor.name]</binding>
       <binding name="propertyDescriptor">descriptor</binding>
   </component>

AssociationMgt.jwc
<!DOCTYPE component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";>
<component-specification class="org.trails.component.AssociationMgt"
           allow-body="yes"
           allow-informal-parameters="yes">

   <property name="nextPage" />

   <property name="delegator"/>

<bean name="numberValidator" class="org.apache.tapestry.valid.NumberValidator" lifecycle="page">
       <set name="valueType">"int"</set>
   </bean>

   <component id="addButton" type="Submit">
       <binding name="listener">listener:addNew</binding>
       <binding name="defer">true</binding>
       <binding name="disabled">page.isModelNew()</binding>
   </component>
   <component id="removeButton" type="Submit">
       <binding name="listener">listener:remove</binding>
       <binding name="defer">false</binding>
       <binding name="disabled">page.isModelNew()</binding>
   </component>

   <component id="editLink" type="EditLink">
       <binding name="model">value</binding>
   </component>
   <component id="linkInsert" type="Insert">
       <binding name="value">value</binding>
   </component>

   <parameter name="createExpression" required="no">
<description>Ognl expression to invoke on the model to create a new association instance</description>
   </parameter>
</component-specification>


AssociationSelect.jwc
<!DOCTYPE component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> <component-specification class="org.trails.component.AssociationSelect" allow-body="yes" allow-informal-parameters="yes"> <description>produces a select list for an association property</description>

   <parameter name="criteria" required="no"/>

<parameter name="allowNone" required="no" default-value="not(propertyDescriptor.required)" /> <!-- inline <parameter name="model" default-value="page.model" required="no"/> -->
   <!-- inline <parameter name="propertyDescriptor" required="yes"/> -->
   <!-- inline <parameter name="owner" required="yes" /> -->
   <!-- inline <parameter name="association" required="yes" /> -->

   <property name="propertySelectionModel"/>

<component id="select" type="PropertySelection" inherit-informal-parameters="yes">
       <!-- <binding name="model">propertySelectionModel</binding> -->
       <!-- <binding name="value">value</binding> -->
   </component>

</component-specification>


AssociationMgt.html
<span jwcid="$content$">
   <tr>
       <td>
           <span jwcid="@If" condition="ognl:not(page.isModelNew())">
           <span jwcid="@If" condition="ognl:association">
<a href="#" jwcid="editLink" model="association" ><span jwcid="linkInsert" /></a>
           </span>
           </span>
       </td>
   </tr>
   <tr>
       <td><br>
           <div jwcid="@If" condition="ognl:association">
               <input jwcid="removeButton" type="button"
value="ognl:getMessage(@[EMAIL PROTECTED])" />
           </div>
           <div jwcid="@If" condition="ognl:not(page.isModelNew())">
               <input jwcid="addButton" type="button"
value="ognl:getMessage(@[EMAIL PROTECTED])" />
           </div>
       </td>
   </tr>
</span>



AssociationSelect.html
<span jwcid="$content$">
   <span jwcid="select"
           value = "ognl:model[propertyDescriptor.name]"
           model = "ognl:propertySelectionModel"
       />
</span>

AssociationSelect.JAVA
package org.trails.component;

import ognl.Ognl;
import ognl.OgnlException;

import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.trails.descriptor.DescriptorService;
import org.trails.descriptor.IClassDescriptor;
import org.trails.descriptor.IPropertyDescriptor;
import org.trails.page.EditPage;
import org.trails.page.PageResolver;
import org.trails.persistence.PersistenceService;

/**
* @author Chris Nelson
*
* This guy interacts with persistence service to produce a Select containing
* all the elements of the PropertyDescriptor's type. If a criteria is
* specified, it will filter the list by it.
*
* Additionally, a detached criteria is available to automatically filter out
* associations without owners, or get all owners by default.
*
*/
public abstract class AssociationSelect extends BaseComponent {
   @InjectObject("spring:persistenceService")
   public abstract PersistenceService getPersistenceService();

   @InjectObject("spring:descriptorService")
   public abstract DescriptorService getDescriptorService();

   @InjectObject("spring:pageResolver")
   public abstract PageResolver getPageResolver();

   public abstract IPropertySelectionModel getPropertySelectionModel();
   public abstract void setPropertySelectionModel(
           IPropertySelectionModel PropertySelectionModel);

   public abstract DetachedCriteria getCriteria();
   public abstract void setCriteria(DetachedCriteria Criteria);

   @Parameter(required = true, cache = true)
   public abstract Object getModel();
   public abstract void setModel(Object bytes);

   @Persist
   public abstract Object getValue();
   public abstract void setValue(Object value);

   @Parameter(required = true, cache = true)
   public abstract IPropertyDescriptor getPropertyDescriptor();
public abstract void setPropertyDescriptor(IPropertyDescriptor propertyDescriptor);

   @Parameter(required = true, cache = true)
   public abstract Object getOwner();
   public abstract void setOwner(Object owner);

   @Parameter(required = true, cache = true)
   public abstract Object getAssociation();
   public abstract void setAssociation(Object association);

   public abstract boolean isAllowNone();
   public abstract void setAllowNone(boolean allowNone);

   public abstract String getNoneLabel();
   public abstract void setNoneLabel(String noneLabel);

   public String getOwnerTypeName() {
       return getOwner().getClass().getName();
   }

   public Class getOwnerType() {
       return getOwner().getClass();
   }

   public String getAssociationTypeName() {
       return getPropertyDescriptor().getPropertyType().getCanonicalName();
   }

   public Class getAssociationType() {
       return getPropertyDescriptor().getPropertyType().getClass();
   }

   public AssociationSelect() {
       super();
   }

   public IClassDescriptor getClassDescriptor() {
       return getDescriptorService().getClassDescriptor(
               getPropertyDescriptor().getPropertyType());
   }

   @Override
   protected void prepareForRender(IRequestCycle cycle) {
       buildSelectionModel();

       super.prepareForRender(cycle);
   }

   protected void cleanupAfterRender(IRequestCycle cycle) {
       super.cleanupAfterRender(cycle);
       //ownerEditPage = (EditPage) cycle.getPage();
   }

   public void buildSelectionModel() {
       DetachedCriteria criteria = getCriteria() != null ? getCriteria()
               : getAllAssociations();
IdentifierSelectionModel selectionModel = new IdentifierSelectionModel(
               getPersistenceService().getInstances(criteria),
               getClassDescriptor().getIdentifierDescriptor().getName(),
               isAllowNone());
       selectionModel.setNoneLabel(getNoneLabel());
       setPropertySelectionModel(selectionModel);
   }

   public DetachedCriteria getAssociationsWithoutOwners() {
DetachedCriteria criteria = DetachedCriteria.forClass(getClassDescriptor().getType());
       try {
//EditPage page = (EditPage) Ognl.getValue("page", getContainer().getPage()); EditPage page = (EditPage) getPage().getRequestCycle().getPage(); String ownerOgnlIdentifier = page.getClassDescriptor().getIdentifierDescriptor().getName(); String associationOgnlIdentifier = getClassDescriptor().getIdentifierDescriptor().getName(); String inverseOgnlProperty = getPropertyDescriptor().getName(); // league

           if (getOwner() != null) {

               criteria.add(Restrictions.disjunction().add(
                       Restrictions.isNull(inverseOgnlProperty)).add(
                       Restrictions.eq(inverseOgnlProperty + "."
                               + associationOgnlIdentifier, Ognl.getValue(
                               ownerOgnlIdentifier, getOwner()))));

           } else {
               criteria.add(Restrictions.isNull(inverseOgnlProperty));
           }
       } catch (OgnlException e) {
           e.printStackTrace();
       }
       return criteria;
   }

   public DetachedCriteria getAllAssociations() {
       DetachedCriteria criteria = DetachedCriteria
               .forClass(getClassDescriptor().getType());
       return criteria;
   }
}

AssociationMgt.JAVA
package org.trails.component;

import java.util.Iterator;

import ognl.Ognl;
import ognl.OgnlException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.Bean;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.annotations.InjectState;
import org.apache.tapestry.annotations.Lifecycle;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.callback.ICallback;
import org.apache.tapestry.components.Insert;
import org.trails.TrailsRuntimeException;
import org.trails.callback.AssociationCallback;
import org.trails.callback.CallbackStack;
import org.trails.callback.EditCallback;
import org.trails.descriptor.BlockFinder;
import org.trails.descriptor.DescriptorService;
import org.trails.descriptor.IClassDescriptor;
import org.trails.descriptor.IDescriptor;
import org.trails.descriptor.IPropertyDescriptor;
import org.trails.descriptor.ObjectReferenceDescriptor;
import org.trails.descriptor.OwningObjectReferenceDescriptor;
import org.trails.page.EditPage;
import org.trails.page.PageResolver;
import org.trails.page.TrailsPage.PageType;
import org.trails.persistence.PersistenceException;
import org.trails.persistence.PersistenceService;
import org.trails.validation.TrailsValidationDelegate;

/**
* @OneToOne use case.
*
* This guy manages the owning side user interface of a OneToOne association.
*
* Owner-<>-----Association
*
* @author kenneth.colassi [EMAIL PROTECTED]
*/
@ComponentClass(allowBody = true, allowInformalParameters = true)
public abstract class AssociationMgt extends TrailsComponent {
protected static final Log LOG = LogFactory.getLog(AssociationMgt.class);

   @Bean(lifecycle = Lifecycle.REQUEST)
   public abstract TrailsValidationDelegate getDelegate();

   public abstract String getCreateExpression();

   public abstract void setCreateExpression(String CreateExpression);

   @Parameter(required = true, cache = true)
   public abstract IPropertyDescriptor getDescriptor();

   public abstract void setDescriptor(IPropertyDescriptor descriptor);

   @Parameter(required = true, cache = true)
   public abstract Object getOwner();

   public abstract void setOwner(Object owner);

   @Parameter(required = true, cache = true)
   public abstract Object getAssociation();

   public abstract void setAssociation(Object association);

   @Parameter(required = true, cache = true)
   public abstract Object getValue();

   public abstract void setValue(Object value);

   @Parameter(required = true, cache = true)
   public abstract Object getModel();

   public abstract void setModel(Object bytes);

   @InjectState("callbackStack")
   public abstract CallbackStack getCallbackStack();

   @InjectObject("spring:pageResolver")
   public abstract PageResolver getPageResolver();

   @InjectObject("spring:persistenceService")
   public abstract PersistenceService getPersistenceService();

   @InjectObject("spring:editorService")
   public abstract BlockFinder getBlockFinder();

   @InjectObject("spring:descriptorService")
   public abstract DescriptorService getDescriptorService();

   public IClassDescriptor getClassDescriptor() {
       return getDescriptorService().getClassDescriptor(
               getDescriptor().getPropertyType());
   }

   public AssociationMgt() {
       super();

       // if (getValue() != null)
       // this.setAssociation(getValue());
   }

   public String getOwnerTypeName() {
       return getOwner().getClass().getName();
   }

   public Class getOwnerType() {
       return getOwner().getClass();
   }

   public String getAssociationTypeName() {
       return getDescriptor().getPropertyType().getCanonicalName();
   }

   public Class getAssociationType() {
       return getDescriptor().getPropertyType().getClass();
   }

   /*
    * public IPage edit(Object association) { EditCallback callback = new
    * EditCallback( getPage().getRequestCycle().getPage().getPageName(),
    * getModel()); getCallbackStack().push(callback); EditPage editPage =
    * (EditPage)getPageResolver().resolvePage( getPage().getRequestCycle(),
* Utils.checkForCGLIB(association.getClass()).getName(), PageType.EDIT); try {
    * getPersistenceService().reattach(association); } catch
    * (NonUniqueObjectException e) { association =
* getPersistenceService().reload(association); } editPage.setModel(association);
    * return editPage; }
    */

   protected void prepareForRender(IRequestCycle arg0) {
       super.prepareForRender(arg0);

       if (getValue() != null) {
           setAssociation(getValue());
       }
   }

   AssociationCallback buildCallback() {
       AssociationCallback callback = new AssociationCallback(getPage()
               .getRequestCycle().getPage().getPageName(), getModel(),
               getObjectReferenceDescriptor());
       return callback;
   }

   public void addNew(IRequestCycle cycle) {
       getCallbackStack().push(buildCallback());

       String currentEditPageName = getPage().getRequestCycle().getPage()
               .getPageName();
       EditPage ownerEditPage = (EditPage) getPageResolver().resolvePage(
               cycle, getDescriptor().getClass().getName(), PageType.EDIT);

       try {
           boolean isNewModel = true;

           // Object newModel = createModel();
           Object newModel = buildNewMemberInstance();
           // AssociationCallback nextPage = new AssociationCallback(
           // ownerEditPage.getPageName(), newModel, isNewModel,
           // ownerEditPage);
           EditCallback nextPage = new EditCallback(ownerEditPage
                   .getPageName(), newModel);

           /**
* This guy gets invoked implicitly on SUBMIT button method after
            * this call ...EditPage.onFormSubmit(...) ... who tracks all
            * submissions... and subsequently triggers
            * EditCallback.performCallback(...)
            * getNextPage().performCallback(cycle);
            *
            * sends us to association editor page
            */
           // ownerEditPage.getCallbackStack().push(nextPage);
           ((EditPage) cycle.getPage(currentEditPageName))
                   .setNextPage(nextPage);
       } catch (Exception ex) {
           throw new TrailsRuntimeException(ex);
       }
   }

   protected Object createModel() throws InstantiationException,
           IllegalAccessException {
       return getDescriptor().getPropertyType().newInstance();
   }

   protected Object buildNewMemberInstance() throws InstantiationException,
           IllegalAccessException {
       Object associationModel;
       if (getCreateExpression() == null) {
associationModel = getDescriptor().getPropertyType().newInstance();
       } else {
           try {
               associationModel = Ognl.getValue(getCreateExpression(),
                       getOwner());
           } catch (OgnlException oe) {
               oe.printStackTrace();
               return null;
           }
       }

       if (getObjectReferenceDescriptor().getInverseProperty() != null
               && getObjectReferenceDescriptor().isOneToOne()) {
           try {
               Ognl.setValue(getObjectReferenceDescriptor()
.getInverseProperty(), associationModel, getOwner());
           } catch (OgnlException e) {
               LOG.error(e.getMessage());
           }
       }

       return associationModel;
   }

   EditCallback buildOwnerCallback(IRequestCycle cycle) {
       EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle,
               getDescriptor().getClass().getName(), PageType.EDIT);

       EditCallback callback = new EditCallback(getPage().getRequestCycle()
               .getPage().getPageName(), editPage.getModel());
       return callback;
   }

   EditCallback buildAssociationCallback(IRequestCycle cycle) {
       EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle,
               getDescriptor().getClass().getName(), PageType.EDIT);

       EditCallback callback = new EditCallback(getPage().getRequestCycle()
               .getPage().getPageName(), editPage.getModel());
       return callback;
   }

   /*
    * AssociationCallback buildOwnerCallback(IRequestCycle cycle) { boolean
    * isNewModel = false; EditPage ownerEditPage = (EditPage)
    * getPageResolver().resolvePage( cycle,
* getDescriptor().getClass().getName(), PageType.EDIT); AssociationCallback
    * callback = new AssociationCallback(ownerEditPage .getPageName(),
    * getOwner(), isNewModel, ownerEditPage); return callback; }
    *
    * AssociationCallback buildAssociationCallback(IRequestCycle cycle) {
    * boolean newModel = true; String currentEditPageName =
* getPage().getRequestCycle().getPage() .getPageName(); AssociationCallback
    * callback = new AssociationCallback( ((EditPage)
    * cycle.getPage(currentEditPageName)).getPageName(), getAssociation(),
    * newModel); return callback; }
    */

   public void remove(IRequestCycle cycle) {
       EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle,
               getDescriptor().getClass().getName(), PageType.EDIT);
       try {
           getPersistenceService().remove(getAssociation());
           editPage.setModel(getPersistenceService().reload(
                   editPage.getModel()));
           cycle.activate(editPage);
       } catch (PersistenceException pe) {
           getDelegate().record(pe);
           return;
       }

ICallback callback = editPage.getCallbackStack().popPreviousCallback();
       callback.performCallback(cycle);
   }

   public abstract EditLink getEditLink();

   public abstract Insert getLinkInsert();


   public OwningObjectReferenceDescriptor getObjectReferenceDescriptor() {
       /*
       ObjectReferenceDescriptor ord = null;
       for (Iterator iter = getDescriptorService().getClassDescriptor(
               getDescriptor().getPropertyType()).getPropertyDescriptors()
               .iterator(); iter.hasNext();) {
           IDescriptor descriptor = (IDescriptor) iter.next();
           boolean foundOrd = false;
           boolean foundOwd = false;

           if (descriptor instanceof ObjectReferenceDescriptor) {
               ord = (ObjectReferenceDescriptor) descriptor;

OwningObjectReferenceDescriptor owd = (OwningObjectReferenceDescriptor) ord.getParentClassDescriptor().getPropertyDescriptors().get(getDescriptor().getIndex());

if (ord.getInverseProperty().equals(owd.getInverseProperty())) {
                   foundOrd = true;
                   break;
               }
           }

       }

       return ord;
       */

       return (OwningObjectReferenceDescriptor) getDescriptor();
   }

}

_________________________________________________________________
More photos, more messages, more storage—get 2GB with Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to