[
https://issues.apache.org/jira/browse/TAPESTRY-1908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12542197
]
Ezra Epstein commented on TAPESTRY-1908:
----------------------------------------
Got it! So I just do something like what's done in the BeanEditForm directly
in my own page/component:
void onPrepareFromForm()
{
// Fire a new prepare event to be consumed by the container. This is
the container's
// chance to ensure that there's an object to edit.
_resources.triggerEvent(Form.PREPARE, null, null);
if (_object == null) _object = createDefaultObject();
assert _object != null;
}
private Object createDefaultObject()
{
Class type = _resources.getBoundType("object");
try
{
return type.newInstance();
}
catch (Exception ex)
{
throw new
TapestryException(InternalMessages.failureInstantiatingObject(
type,
_resources.getCompleteId(),
ex), _resources.getLocation(), ex);
}
}
Thanks!
> BeanEditorForm does not use class supplied via optional model
> -------------------------------------------------------------
>
> Key: TAPESTRY-1908
> URL: https://issues.apache.org/jira/browse/TAPESTRY-1908
> Project: Tapestry
> Issue Type: Bug
> Components: tapestry-core
> Affects Versions: 5.0.6
> Environment: Java 1.5
> Reporter: Ezra Epstein
>
> The guide document for the BeanEditForm
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/beaneditform.html
> states under the "Providing the BeanModel" heading: "...For example, if the
> the type of the property being edited is an interface type, it may be useful
> to provide an explicit BeanModel around an underlying implementation class."
> I've been trying this and get a variety of exceptions depending on which way
> I go.
> .tml:
> <form t:type="beaneditform" object="entity" model="model" />
> .java:
> If getEntity() returns the exact concrete class this works fine. But,
> if getEntity() returns a concrete superclass a ClassCastException is thrown.
> If getEntity() returns an interface or an abstract superclass then a
> org.apache.tapestry.ioc.internal.util.TapestryException is thrown with a
> message stating: "Exception instantiating instance of ..."
> I'm guessing that the BeadEditorForm is using the return type of the
> getEntity() method in preference to the class I specify on the model.
> Note: the use case is a bit hyper-dynamic and sneaky. I'm using (or trying
> to use) Tap5 as an HTML front-end to a generic REST entity service. The
> service takes XML and I wanted to add a simple HTML interface to it. Thus
> the actual class of the entity is determined via a request parameter. I can
> dynamically set the class in the model but not the getEntity()'s return type.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]