How do you create a component in Tapestry 5?

I use the built-in components of Tapestry, but now I would like to try to make my own. Assuming this is possible, how is it done, and is it usually assumed that developers will create their own components in addition to what goes out of the box?

+3
source share
3 answers

Yes, it is expected that developers will create their own components, and this is pretty easy to do. There are many projects where people create their component libraries. If you want to see some examples, check out:

. .tml .java. .java src, (src/main/java/com/examples/app/components), .tml , (src/main/resources/com/examples//)

, Facebook, EventInfo Event, URL-, Facebook.

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.persistence.Transient;

import net.xeric.register.entities.Event;

import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PageRenderLinkSource;

public class ShareEventOnFacebook {

    @Inject
    private PageRenderLinkSource linkSource;

    @Parameter(required=true)
    @Property
    private Event event;


    public String getFacebookShareURL() {
        Link link = linkSource.createPageRenderLinkWithContext("EventInfo", event);
        String linkURL = "";
        try {
            linkURL =  URLEncoder.encode(link.toAbsoluteURI(),"UTF-8");
        } catch (UnsupportedEncodingException e) {

            e.printStackTrace();
        }
        return linkURL;
    }

    public String getFacebookShareTitle() {
        String returnValue = "";
        try {
            returnValue = URLEncoder.encode(event.getDescription(), "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;       
    }

}

, Event , . , , <t:shareeventonfacebook event="myEvent"/>

:

<t:container 
    xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">


    <a href="http://www.facebook.com/sharer.php?u=${facebookShareURL}">
        Share on Facebook
    </a><br/>

</t:container>

, :

<t:shareeventonfacebook event="event"/>
+6

, . : , , . - , .

, , .

+2

, ( - ). :

  • ( )

, - Tapestry .

+2

Source: https://habr.com/ru/post/1785452/


All Articles