I just went ahead and created the mixin based on the equanda TextField
component, as far as I can see, it works nicely. The mixin lets any event on
any component update a zone. The only requirement is that the HTML element
has a "value" attribute. This limitation could easily be erased as well, I
guess. Right now I don't need to.

The only thing I see that is a little bit "dirty" is the way that equanda
puts the entered value into the link string. Is there any way to make it
easier to do this kind of thing natively in T5? Perhaps through a different
approach entirely?


Usage and source code:


TML:
<input t:type="textField" t:id="searchField" value="search" zone="list"
event="keypress" t:mixins="zoneUpdater"/>

JAVA:
- Provide a listener, in this case "onKeyPressFromSearchField", that returns
a Block the usual zone way.


SOURCE:
package myapp.frontend.tapestry5.mixins;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ClientElement;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.ioc.annotations.Inject;

@IncludeJavaScriptLibrary("classpath:/org/equanda/tapestry5/resources/equanda.js")
public class ZoneUpdater {

  @Inject
  private ComponentResources resources;

  @Environmental
  private RenderSupport renderSupport;

  @Parameter(defaultPrefix = BindingConstants.LITERAL, required = true)
  private String event;

  @InjectContainer
  private ClientElement element;

  @Parameter
  private Object[] context;

  @Parameter(defaultPrefix = BindingConstants.LITERAL, required = true)
  private String zone;

  protected Link createLink(Object[] contextArray) {
    return resources.createEventLink(event, contextArray);
  }

  void afterRender(MarkupWriter writer) {
      String urlStart = createLink(context).toAbsoluteURI();
      String urlEnd = "";
      int pos = urlStart.indexOf(';');
      if (pos > 0) {
        urlEnd = urlStart.substring(pos);
        urlStart = urlStart.substring(0, pos);
      }
      renderSupport.addScript("element = $('%s');\n" +
      // Update the element with the id of zone div. This may be changed
dynamically on the client side.
          "$T(element).zoneId = '%s';\n" + "element.observe(\"" + event +
"\", function(event) { eqTfzu( event, '%s/', '%s' ); });\n",
element.getClientId(), zone, urlStart, urlEnd);
    }

}


On Mon, Feb 16, 2009 at 12:59 PM, Inge Solvoll <inge.tapes...@gmail.com>wrote:

> Don't know if this is a bad thing to ask about here, you just tell me if I
> should take this business elsewhere... :)
>
> In equanda-tapestry5 I discovered a very nice and useful component,
> TextField, which updates a zone through the onchange event of a regular
> textfield. This is excactly what I've been looking for, except that I need
> to be able to specify an event other than "change". I've looked at the
> source code, and it seems trivial to make the event a parameter. For now, I
> will make this change in my own copy of this component, but I would love to
> see this implemented in the equanda component!
>
> Also, wouldn't it be cleaner to provide this component as a mixin? If
> possible? I think I'll try that, I'll post the result here if I'm successful
> :)
>
> Regards
>
> Inge
>

Reply via email to