Dashboard > RIFE > ... > Web engine > Embedded elements
RIFE Log In | Sign Up   View a printable version of the current page.
Embedded elements


Added by Geert Bevin, last edited by Geert Bevin on Jul 31, 2006  (view change)
Labels: 
(None)

Other examples:

Purpose

RIFE supports embedded elements. This makes it possible to display elements inside the template of another element by using the special value tag format :

<!--V 'ELEMENT:elementid'/-->

[top]

Isolation

Embedded elements are isolated and can't interfere with their enclosing element in most situations.
Embedded elements are however able to modify globalvars if output vars with the same name have values. For example, consider the following site :

<site>
    <globalvar name="authid"/>
    <element id="AUTHENTICATION" file="authentication.xml"/>
    <element id="CREDENTIALS" file="credentials.xml"  inherits="AUTHENTICATION"/>
    <element id="HOME" file="home.xml" url="home"/>
</site>

Where the template of the HOME element contains the following value tag :

<!--V 'ELEMENT:.CREDENTIALS'/-->

When the authentication succeeds, the AUTHENTICATION element will set an output var 'authid' with the valid authentication id of the user that just logged in. This output var corresponds to the globalvar 'authid', which means that it will modify it and that the HOME element in itself will receive the correct 'authid' value after the login and before the processing of the element. Otherwise, the globalvar would just be empty.

Now notice that the CREDENTIALS element doesn't contain an url mapping in the site structure. This defines it as a pure embedded element and will cause all its submissions to be sent to the url of the enclosing element (HOME here). The result is that when someone logs in through the embedded element, the response page will again contain the content of the HOME element, but with an updated (authenticated) content for the CREDENTIALS element. The submission thus doesn't 'break out' of the design anymore and keeps the element embedded.

[top]

Manual processing

Since embedded elements are able to modify the context, it's sometimes important to explicitly replace the element embedding value tag manually instead of letting RIFE do it automatically. You can do this with the Element::processEmbeddedElement(Template template, String elementid) method. Its use can be very handy when the order becomes important if you also manually replace exit value tags with setExitQuery() or setExitForm().

[top]

Embed values

When embedding elements in templates, you can access the default value from within the embedded elements. This is handy when you have modular embedded elements that have to be setup for different uses when they are inserted in the templates.

For example, consider this template snippet:

The element "<!--V 'ELEMENT:.SIMPLE'-->this is the value<!--/V-->" is being embedded.

Inside the SIMPLE element's implementation, you can now use the getEmbedValue() method, which will in this case return:

this is the value

[top]

Component example

Here is an example of using an embedded element to create a component, by Eddy Young. Reference: http://article.gmane.org/gmane.comp.java.rife.user/2284

The example is a simple label.

sites/main.xml
<subsite id="Components">
  <element id="Label" implementation="web.components.Label">
  </element>
</subsite>
templates/test.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>View profile</title>
  </head>
  <body>
    <!--V 'content' /-->
    <!--BV 'content'-->
      <p>This is your profile.</p>
      <p>Username: <!--V 'ELEMENT:^Components.Label'-->
                    id = username
                    value = uname
                   <!--/V-->
    <!--/BV-->
  </body>
</html>
web.components.Label
/*
 * Label.java
 *
 * $Id$
 */

package web.components;

import com.uwyn.rife.engine.Element;
import java.util.Properties;

/**
 *
 *  @author Eddy.Young
 *  @version $Revision$
 */
public class Label extends Element {
    private String id;
    private String value;

    public void processElement() {
        Properties properties = getEmbedProperties();
        id = properties.getProperty("id");
        value = properties.getProperty("value");
        print("<label id=" + id + ">" + getInput(value) + "</label>");
    }
}

The interesting thing here is that the ELEMENT:<name> tag can embed more than one value. This can be used to specify parameters. For example, for a "list" component, the parameter could be the name of a bean that contains the entries. Another parameter could be the name of a template.

The possibilities are virtually limitless. It would be great if those who have used embedded elements to create components could share their experience here.

[top]



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