Steven,

 Could you add your Annotations information to the Best Practices
page in the wiki? I'd like to start using your format (seems to reduce
some clutter), but I'm not 100% sure on what your site.xml ends up
looking like.

Thanks,
 Tyler

On 7/11/06, Steven Grimm <[EMAIL PROTECTED]> wrote:
This is a followup to my earlier email about best practices for
annotations. As of the latest snapshot, RIFE now has support for a
couple of new annotations that have made me move the last of my
configuration out of the XML files. Now my XML config is mostly just a
list of <element> tags with URLs and implementation class names.
("Mostly" because I am still configuring built-in RIFE elements in the
XML, e.g. the authentication element.)

Now I can define my site structure without repeating information in my
code. Here's what it looks like with the new annotations:

@Elem(
    url = ""    // An embedded element
)
public class ProductListEntry extends AbstractProductProvider {
    @FlowlinkExitField(destClass = EditProduct.class,
            destClassIdPrefix = ".Admin.",
            datalinks = {
                @Datalink(srcOutput="productId", destInput="productId")
            })
    public static final String EXIT_EDIT_PRODUCT = "editProduct";

    @FlowlinkExitField(destClass = ShowProduct.class,
            datalinks = {
                @Datalink(srcOutput="productId", destInput="productId")
            })
    public static final String EXIT_SHOW_PRODUCT = "showProduct";

    @OutputProperty
    public int getProductId() {
        if (_product != null)
            return _product.getId();
        return 0;
    }

    public void processElement() {
        ...
        exit(EXIT_SHOW_PRODUCT);
    }


Notice that I don't explicitly declare any exits -- the
@FlowlinkExitField annotation does that implicitly. And thanks to the
destClassIdPrefix attribute (which is also present on the @Exit
annotation) I can now refer to a destination class rather than an ID
even if the element is in another subsite. I also define my datalinks in
the context of my flowlinks, which I hadn't noticed I could do when I
sent my previous mail. I think that makes it a lot easier to follow.

The only place where I'm still repeating myself here is that I have the
exit names in my templates (in the form of ${v EXIT:QUERY:showProduct/}
etc.) I'm not doing this, but it's possible to get rid of those too if
you want to be very strict about not duplicating exit names:

    template.setValue("showProductUrl",
                      getExitQueryUrl(EXIT_SHOW_PRODUCT));

    <a href="${v showProductUrl/}">...</a>


That will automatically fetch any required output values and add them to
the URL. I don't do that because it doesn't reduce the number of times I
have to repeat myself -- I still have to have the template value name in
both places anyway. But if you do it that way then your actual exit
names would become totally irrelevant, if that's a plus for you.

Anyone else doing something different they want to share?

-Steve
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to