import

toc
<mm:import> To put objects in the context. That is, import a variable from an external source (a parent context, parameters, a form (post parameters) or the session). You can also create a new variable with this.
see alsocontext | write | contextreferrer
attributes
  • id (Either `id' or `externid' or both must be supplied.)
    This is the key by which the object will be registered in the context. This key may not already exist. You must use the remove tag first, if you need to change the value of the registered object. If you do not supply this attribute, it is supposed to have the same value as `externid' which should be present then.
  • externid (Either `id' or `externid' or both must be supplied.)

    The `externid' is the name of an attribute in the session, parameter in the request, or id in the parent context. The value of this thing is imported in the current context, with the id given by the attribute `id'.

    If there is no attribute `externid' then the value of the new object in the context is taken from the body of this import tag. In that way you can create a variable.


  • required
    Whether the object to be imported is required. If nothing can be found by externid and a default value in the body is missing too, then an exception will follow. It is advised to use this on pages which do nothing sensible without a value for this. Typically read-more pages and so on, which simply cannot show anything if they are not informed what to show. This also serves to document the implementation of the JSP, because the imported variables marked as 'required' are at once recognizable as essential for the page's functionality.
  • reset

    On default, this tag will throw an exception if the id to be registered is registered already. This will protect you against accidentally using the same id twice, thus obfuscating your code.

    If though you really want it then you can set the attribute `reset' to true.

    Consider also `scoping' your variables with a mm:context tag (especially useful for static includes).


    see: context
  • from
    Where to search the externid in. On default it is searched in several sources, but you can limit it with this attribute. In this way it is also possible to get different variables with the same name from different sources.
    parent Imports the variable from a parent context.
    page Import the variable from the standard JSP `page context'.
    session Import the variable from the session.
    cookie Import the variable from a user cookie.
    parameters Import the variable from a POST (a simple form) or GET (the URL) parameter.
    multipart If the form is a `multipart' form (enctype="multipart/form-data"), which is necessary e.g. for images, then you can read the results with this. `postparameters' is a synonym for this, but `multipart' is probably a clearer description.
    multipart? As multipart, if that is possible. Ignored otherwise. If you specify 'multipart' but the request is not a multipart post, it would otherwise give an error.
    request There can be attributes set on a request object. These are principally importable into taglib as well. See JavaDoc.
    application There can be attributes set on the `application'.
    this Especially when you use a list of `from' locations, then the `this' location can be useful. It represent the current value, if there is one. Using this implies reset="true" (because of course you want to reset if current value is an option).
    parameters,session You can also specify a list of locations. This one means: If an attribute cannot be found in the parameters, try it in the session.
  • jspvar
    If you specify `jspvar' a JSP-variable with this name will be created too. It is available after the closing of the tag. JSP-variables can also be created with the `write' tag. A write tag has more precise scoping possibilities.
    see: jspvar attribute of writer
  • vartype
    see: vartype attribute of writer
  • escape
    The import tag does not write anything to the page, so for that the `escape' attribute is not useful. The escape attribute from the import tag is therefore used to escape the actual value of the generated taglib variable. You can for example use it to uppercase an URL parameter or so (for searching).
    see: escape attribute of writer
  • listdelimiter (since: MMBase-1.8)
    If the vartype is 'list', but a String is received, then it will be converted to a List of String, using this delimiter. It defaults to a comma.
contextreferrer attributes
example 1
<!-- Create a variable `hoi' from the parameter `haj',
     Generate an exception if this parameter is not present -->
<mm:import id="hoi" externid="haj" from="parameters" required="true" />
example 2
<!-- Create a variable `hoi' from the parameter `haj',
     If this parameter is not present, hoi becomes `hello' -->
<mm:import id="hoi" externid="haj" from="parameters" >hello</mm:import>
example 3
<!-- Create a variable `hoi' with value `hello' -->
<mm:import id="hoi">hello</mm:import>
example 4
<!-- Create a variable `hoi'. The value will come from an external source,
like the parameter list or the session (where ever it is available) -->
<mm:import externid="hoi" />