Howard? Anyone? Help! My tapestry 3 component is completely dead in tapestry
4!
Here is the component's java file:
public abstract class AnchoredBlock extends CollectiveComponent
{
private int linksFound;
private static LogFacade log = LogFacade.getLog(AnchoredBlock.class);
public String getAnchorName()
{
return getId();
}
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
linksFound = 0;
// long startTime = System.currentTimeMillis();
Set links = findDirectLinks(this);
addAnchors(links);
// log.info(System.currentTimeMillis() - startTime + "ms AnchorBlock anchor
insertion time");
// log.info("Modified " + links.size() + " links out of " + linksFound);
super.renderComponent(writer, cycle);
}
private void addAnchors(Set links)
{
for (Iterator iter = links.iterator(); iter.hasNext();)
{
DirectLink link = (DirectLink) iter.next();
link.setProperty("anchor", getAnchorName());
}
}
private Set findDirectLinks(AbstractComponent component)
{
Set links = new HashSet();
doRecursion(component, links);
return links;
}
private void doRecursion(AbstractComponent component, Set links)
{
if(component.getComponents().isEmpty() && component.getBody() == null)
return;
if (component instanceof DirectLink)
{
linksFound++;
links.add(component);
return;
}
if(component.getBody() != null)
{
for (int i = 0; i < component.getBody().length; i++)
{
IRender thingy = component.getBody()[i];
if(thingy instanceof AbstractComponent)
{
doRecursion((AbstractComponent)thingy, links);
}
}
}
if(!component.getComponents().isEmpty())
{
for (Iterator iter = component.getComponents().keySet().iterator();
iter.hasNext();)
{
IComponent thingy = (IComponent) component.getComponent
((String)iter.next());
if(thingy instanceof AbstractComponent)
{
doRecursion((AbstractComponent)thingy, links);
}
}
}
}
}
On 9/1/05, Chris Norris <[EMAIL PROTECTED]> wrote:
>
> I see. Well let me back up to the larger problem then.
>
> With the last version of the code I had a component called
> AnchoredBlock. The component would render an anchor tag at the top and
> then would add an anchor to every DirectLink contained inside of it.
> This was needed so that if there were, for instance, 10 tables on a
> page, and each one had sortable headers, you could click on a header on
> the 10th table and not have the page refresh at the top again. You'd
> still be at the bottom due to the anchor tag and the anchors added to
> the direct link. It was really easy to use this component because you
> could just wrap it around anything and it didn't require any parameters.
> Without it, I'd have to pass anchor tags very, very deep in some cases,
> and when I went down that route it got very ugly very quickly. I could
> easily pass an anchor 5 components deep just to get it to the
> DirectLink.
>
> With the last version of tapestry, I did that by recursively finding
> every component inside of the AnchoredBlock and calling
> setProperty("anchor", getAnchorName()) on the DirectLinks. This seemed
> to work pretty well. Now I get a message that my parameter "anchor"
> isn't bound and therefore I can't update it. So what can I do here? I
> feel like I'm just going about it all wrong now.
>
> -Chris
>
> -----Original Message-----
> From: Howard Lewis Ship [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 01, 2005 3:26 PM
> To: Tapestry users
> Subject: Re: Programmatically adding a binding to a component?
>
> It's just as well you can't; you don't want to be adding bindings
> directly. The various setter methods exist for the framework, you
> should treat components as immutable. This is why its going to be good
> for everyone to break the inheretance requirement ... the IComponent
> that will be exposed to your peer code will be entirely immutable.
>
> On 9/1/05, Chris Norris <[EMAIL PROTECTED]> wrote:
> > Is there a way to add a binding to a component programmatically? I
> see
> > that there is a setBinding() method in AbsractComponent, but I can't
> > really figure out how to manually construct an IBinding instance.
> >
> >
> >
>
>
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
>
> Professional Tapestry training, mentoring, support
> and project work. http://howardlewisship.com
>
> ---------------------------------------------------------------------
> 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]
>
>