Dashboard > RIFE > ... > Web engine > Dynamic embedded element differentiators
RIFE Log In | Sign Up   View a printable version of the current page.
Dynamic embedded element differentiators


Added by Geert Bevin, last edited by Geert Bevin on Dec 19, 2005
Labels: 
(None)

In case you're using several embedded elements of the same element ID in the same template, you could already use differentiators before to tell RIFE that they are different and to be able to identify them.

However, we had no solution to for example use an embedded element for each row of a table with editable fields. Dynamic embedded element differentiators solve this.

The processEmbeddedElement(Template template, String elementId, String differentiator) method has been enhanced to support embedded elements with empty differentiators.

a simple example

Let's look at a short example. We are going to create a list with entries that each contain a form and a text input field. Each entry should be able to handle its own form submission, and display the received data afterwards. We are going to create one element that corresponds to an entry (ListEntry) and another one that corresponds to the list (List). The entry element is thus going to be embedded inside the template of the list element.

the List element

Let's look at the List element's template:

<!--V 'divs'/-->
<!--B 'div'-->
    <div><!--V 'counter'/--> <!--V 'ELEMENT:.ListEntry:'/--></div>
<!--/B-->

You clearly see that the ListEntry element ID simply has a colon and no differentiator. This means that RIFE will dynamically add a differentiator according to the value that has been provided for it in the processEmbeddedElement method.

the ListEntry element

The ListEntry element's declaration looks like this:

<element id="ListEntry" implementation="my.pakkage.ListEntry">
    <submission name="changeEntry">
        <param name="value"/>
    </submission>
</element>

has the following template:

<form method="post" action="[!V 'SUBMISSION:FORM:changeEntry'/]" name="form[!V 'differentiator'/]">
    <!--V 'SUBMISSION:PARAMS:changeEntry'/-->
    <input type="text" name="value">
    <input type="submit" />
</form>

and the following implementation:

public class ListEntry extends Element
{
    public void processElement()
    {
        Template t = getHtmlTemplate("listentry");
        t.setValue("differentiator", getEmbedDifferentiator());      
        print(t);
    }

    public void doChangeEntry()
    {
        print(getParameter("value"));
    }
}

Now, the implementation of the List element looks like this:

public class List extends Element
{
    public void processElement()
    {
        Template t = getHtmlTemplate("list");
        for (int i = 0; i < 10; i++)
        {
            t.setValue("counter", i);
            processEmbeddedElement(t, ".LISTENTRY_EMBEDDED", String.valueOf(i));
            t.appendBlock("divs", "div");
        }
        print(t);
    }
}

the result

You'll see a list with 10 entries and thus 10 input fields, they each handle their own submission without you having to do anything besides processing each embedded element with a unique differentiator.



Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators