If you know the set of components that you might render, would the
@RenderBlock/@Block accomplish what you need. We use these components quite
successfully on some very dynamic forms, however we know all the types of
components that could render ahead of time. If this doesn't quite work for
you, you could review Mike's @DynamicBlock component.
Here is an example of how we use @RenderBlock/@Block. Notice the
getComponent call in the @RenderBlock, it looks up a component by name, in
this case we are trying to look up one of the blocks:
<tbody>
<loop jwcid="@Foreach"
source="ognl:loopOrder.prompts"
value="ognl:loopPrompt" element="tr">
<td>
<span jwcid="@Insert"
value="ognl:loopPrompt.description"
/>
</td>
<td>
<span jwcid="@RenderBlock"
block="ognl:getComponent(loopPrompt.type.name)" />
</td>
</loop>
</tbody>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null"
displayName="ognl:loopPrompt.description"
validator="ognl:getDateTimeValidator(loopPrompt, 'MM/dd/yyyy
HH:mm')"
width="15" />
</block>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null"
displayName="ognl:loopPrompt.description"
validator="ognl:getDateTimeValidator(loopPrompt, 'MM/dd/yyyy')"
width="10" />
</block>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@Checkbox" selected="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null" />
</block>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null"
displayName="ognl:loopPrompt.description"
validator="ognl:getNumberValidator(loopPrompt)" width="8" />
</block>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null"
displayName="ognl:loopPrompt.description"
validator="ognl:beans.collectedValidator" width="15" />
</block>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null"
displayName="ognl:loopPrompt.description"
validator="ognl:beans.collectedByValidator" />
</block>
<block jwcid="[EMAIL PROTECTED]">
<if jwcid="@contrib:FormConditional"
condition="ognl:loopPrompt.allowedValues.size == 0">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
disabled="ognl:loopOrder.cancelCondition != null"
displayName="ognl:loopPrompt.description"
validator="ognl:getStringValidator(loopPrompt)" />
</if>
<if jwcid="@contrib:FormConditional"
condition="ognl:loopPrompt.allowedValues.size != 0">
<select jwcid="@ValidPropertySelection"
model="ognl:loopPromptSelectionModel"
value="ognl:loopPrompt.value"
displayName="ognl:loopPrompt.description"
disabled="ognl:loopOrder.cancelCondition != null"
validator="ognl:getPropertySelectionValidator(loopPrompt)" />
</if>
</block>
<block jwcid="[EMAIL PROTECTED]">
<input jwcid="@ValidField" value="ognl:loopPrompt.value"
class="ognl:loopPrompt.isRequired?'field-required':null"
displayName="ognl:loopPrompt.description"
disabled="ognl:loopOrder.cancelCondition != null"
validator="ognl:getDateTimeValidator(loopPrompt,'HH:mm')" width="7"
/>
</block>
-----Original Message-----
From: Robert Cole [mailto:[EMAIL PROTECTED]
Sent: Friday, April 22, 2005 8:11 AM
To: [email protected]
Subject: Using components dynamically
Hi all.
We're in the process of building a very flexible component that we'll use a
lot over our site. The component will render an HTML table with data
populated from a list of objects and properties, the properties forming
columns in the table and the objects forming the rows, with the properties
being applied to the rows to get the cell data.
The problem we're trying to solve is that the type of data that the
properties return from the object are not all of the same type across the
table. For example they could be a string, a double, a percentage or a more
complex custom type. To make it even more interesting we need to specify in
a per-column basis how each of these types should be rendered, for example
maximum length, number of decimal places etc. We've managed to work out much
of the background details but we've hit a bit of a stumbling block when
actually rendering the information in the component.
The current proposal is to use a (potentially) different component for each
data cell. For example if the columns are String, String, Percentage, Price
we would use a standard Insert component for the first two, a Number
component we've written for the third and then a Price component we've
written for the last. Since the structure of the table will only be known
when the component is rendered (i.e. based on the data passed in) we need to
be able to instantiate these components dynamically. We also don't want to
pass in a big list of information as to how to render each property into the
component. We'll do this inside each of the property objects we pass into
the component.
We've had a look around and found a method on the PageLoader implementation
called CreateImplicitComponent which seems to do what we need, but we can't
get at the PageLoader class. We're thinking of writing our own
implementation of this method to instantiate the components we require and
then render the contents of each cell for us. However, we're not sure what
needs to be done here.
Has anyone done anything like this before and can offer some advice, as
we're stumbling in the dark at the moment and we could use a little help.
Thanks,
Rob
--
This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]