Hi, We built a custom component that has its' own renderComponent method. However, rather than create one of these for each "type" of component, we load the component dynamically. So, this "dynamic" component loads others that have been declared in another page. We load thise via string names dynamically.
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) { . . . BaseComponent component = (BaseComponent)pageHolder.getComponent(componentName); if (component instanceof PageRenderListener) { IPage page = component.getPage(); page.beginPageRender(); } component.render(writer, cycle); } The componentName is actually loaded in the method from another source, all it has to be is a string that matches the name in the "pageHolder". The "pageHolder" has components declared in the .html/.page. HTH, Mark -----Original Message----- From: Robert Cole [mailto:[EMAIL PROTECTED] Sent: Fri 4/22/2005 9:11 AM To: tapestry-user@jakarta.apache.org 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]