Category Archives: Tapestry

Using ValueEncoders with Resteasy

The power of Tapestry’s ValueEncoder can be used with RestEasy by implementing javax.ws.rs.ext.ParamConverterProvider

import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.services.ValueEncoderSource;

import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

@Provider
public class ValueEncodersProvider implements ParamConverterProvider {

    private final ValueEncoderSource valueEncoderSource;

    public ValueEncodersProvider(ValueEncoderSource valueEncoderSource) {
        this.valueEncoderSource = valueEncoderSource;
    }

    @Override
    public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
        final ValueEncoder<T> encoder = valueEncoderSource.getValueEncoder(rawType);
        if (encoder == null) {
            return null;
        }

        return new ParamConverter<T>() {
            @Override
            public T fromString(String value) {
                return encoder.toValue(value);
            }

            @Override
            public String toString(T value) {
                return encoder.toClient(value);
            }
        };
    }

}

Changing locale based on domain

Happy New Year to everybody!!.

With Tapestry one of the advantages is that you can override almost everything but then there are always some parts which are less overridable. One such place is setting locale based on some custom criteria. The locale logic is embedded a bit deeper than you expect into the request processing cycle and that might give you an impression that you won’t be able to override it. Continue reading

Tapestry and ‘Editable for Bootstrap’

Twitter Bootstrap is a relief to programmers like me who were never good at web-designing. It has a nice javascript library and there are already modules to integrate twitter-bootstrap with tapestry. There are a lot of good add ons coming up for bootstrap and one of my favourites is the Editable for Bootstrap. Every time I see such a library I wait for a oppurtunity to integrate it with Tapestry.
Continue reading

Scrolling pages : tapestry5 & onScrollBeyond

This blog is about adding pagination in Tapestry 5 using jQuery based onScrollBeyond(). It might sound difficult but as always tapestry makes it so easy that you wonder whether it is worth blogging about :).
Continue reading

Tapestry source code viewer

A simple implementation of a SourceCodeViewer would be to have a service for adding and listing the source code and a component to display it.
Continue reading

Tapestry: Using ComponentRequestFilter

This example is similar to Securing Tapestry pages with Annotations, Part 1. My use case is to redirect a user to the starting page of a multiple step wizard in case a request is directly made to an intermediate step and the session has not been properly setup. One way to solve this problem (the ugly way) is to add a condition to every entry point in the page


public class MyPage
{
    @SessionState(create = false)
    private ShoppingCart shoppingCart;

    @OnEvent(EventConstants.ACTIVATE)
    Object activate()
    {
        if(shoppingCart == null)
        {
           return Index.class;
        }
        return null;
    }

    @OnEvent(EventConstants.SUCCESS)
    Object doSomething()
    {
        if(shoppingCart == null
        {
           return Index.class;
        }

        .....
    }

The problem with this code is that you have to check this condition for all event-handlers(Form, EventLink etc). A more elegant solution would be to use annotation secured by a ComponentRequestFilter.
Continue reading

Tapestry Grid & Hibernate Criteria

Tapestry Grid is a very powerful tool for displaying a list of entities. It expects a GridDataSource as source parameter. A useful tool can be a TypeCoercer which converts a Criteria to GridDataSource. Continue reading

Follow

Get every new post delivered to your Inbox.

Join 91 other followers

%d bloggers like this: