출처: http://blog.naver.com/wildxing?Redirect=Log&logNo=20034798616

lex 2 Tag Library for JSP

The <mxml> tag compiles the MXML code, if required, and then generates the HTML fragment to load Adobe® Flash® Player and the resulting SWF file in your JSP page. You can use do this in two different ways. The source tag attribute lets you specify the source file to compile. This is useful because the JSP tag writes the HTML fragment for you. The other approach is to specify the source as the body content of the tag. Then, you use JSP scriptlets to generate the MXML source.

The <flashvar> tag lets you to pass variables to a Flex application. You access these variables by using the Application.application.parameters object.

Although the Flex 2 Tag Library for JSP is similar to the tag library in Flex 1.x, there are some differences. The tag attributes of the <mxml> tag are simpler; full control of all the HTML wrapper attributes is no longer available. However, the tag library includes attributes that enable history management and Flash Player detection on a per-tag basis. The <param> tag that let you add Flash Player parameters to the HTML wrapper was eliminated in an effort to simplify tag usage. The <flash> tag, which generated an HTML wrapper for a pregenerated SWF file, was eliminated also.

 

 

What is the Flex 2 Tag Library for JSP?


You should use the Flex 2 Tag Library for JSP to do any of the following:

  • Include an MXML (Flex) application within an existing HTML/JSP page.
  • Include history management or Flash Player detection for one application but not another application.
  • Present an MXML application if the correct version of the Flash Player is installed, or an HTML version otherwise.
  • Present one of a few versions of the same basic application determined through logic in a JSP page.

 

What Are the Limitations?

 

If you use the Flex 2 Tag Library for JSP incorrectly, overall application performance can suffer because of excessive recompilation. In general, there are no performance concerns if you use the <mxml> tag and compile MXML source code by using the source attribute.

The following alternate approaches do not modify the actual MXML code that a JSP page generates and do not cause excessive recompilations. Before deciding to use the tag library with your application with inline MXML source code, consider whether one of the following options would be more appropriate:

  • Separate the presentation from the data so that you can use Flex Data Services to populate the data in the application.
  • Pass in the dynamic data by using the <flashvar> tag. You can safely use different name-value pairs on the <flashvar> tag for each JSP page execution, because the differences do not cause a modification and recompilation of the MXML source code.
  • Manipulate the presentation by using ActionScript.

 

What Do I Need to Use It?

 

The Flex 2 Tag Library for JSP requires the following:

  • Flex™ Data Services 2.0.1
  • Flex 2 Tag Library for JSP ZIP file
  • A supported Java application server or servlet container

 

Download and Installation

 

The Flex 2 Tag Library for JSP is only supported when installed upon a licensed version of FDS 2. It is delivered as a zip file containing all relevant files, and must be manually installed for each FDS application. Before starting, if Hotfix 143906 is installed, please remove it by deleting /WEB-INF/flex/hotfixes/fds2_143906.jar. The Flex 2 Tag Library for JSP includes Hotfix 143906.


Note: Your use of this site including software downloads, submission of comments, ideas, feature requests and techniques on this and other Adobe maintained forums, as well as Adobe’s rights to use such materials, is governed by the Terms of Use.


1. Download the ZIP file.

2. Stop the server on which Flex Data Services is running.

3. Unzip the ZIP file to a temporary directory.

4. Copy the flex-bootstrap-jsp.jar file into the /WEB-INF/lib directory.

5. Copy the flex-webtier-jsp.jar file into the /WEB-INF/flex/jars directory.

6. Edit the web.xml file to include the tag-library definition, as the following example shows:

<taglib>
  <taglib-uri>FlexTagLib</taglib-uri>
  <taglib-location>/WEB-INF/lib/flex-bootstrap-jsp.jar</taglib-location>
</taglib>

7. Restart the Flex server.

 

 

How Do I Use the JSP Tag Library?

 

Follow the directions to install the Flex 2 Tag Library for JSP.

1. Add the following tag library declaration to your JSP page:

<%@ taglib uri="FlexTagLib" prefix="mm" %>

2. Use the <mxml> tag to insert a Flex application into an existing JSP page. The following example shows the <mxml> tag with the source attribute to include an external MXML file:

<mm:mxml source="CustomerServiceChat.mxml"/>

Alternatively, you can use the <mxml> tag with inline MXML source code, as the following example shows:

<mm:mxml>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
        <mx:Text label="Hello World">
    </mx:Application>
</mm:mxml>

Use the <mxml> tag carefully, as any JSP execution that results in different MXML source code causes recompilation. Each distinct instance of MXML source code is cached separately and checked for recompilation separately. Two or three distinct versions of MXML source code might be acceptable, but different MXML source code on each compilation would not be.

For example, the following JSP code results in two sets of MXML source code; one is created when request.isUserInRole("admin") is true and another is created when request.isUserInRole("admin") is false:

<mm:mxml>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
        <% if (request.isUserInRole("admin")) { %>
        <AdminConsole/>
        <% } else { %>
        <UserConsole/>
        <% } %>
    </mx:Application>
</mm:mxml>
  • Use the <mxml> and <flashvar> tags to quickly create a dynamic application. Updating the <flashvar> tag does not cause a recompilation. Although the MXML code was specified inline, the source is static without JSP scriptlets.

The following example uses <mxml> and <flashvar> tags with inline MXML code to get the Java version and current date:

<%@ taglib uri="FlexTagLib" prefix="mm" %>

<mm:mxml height="300" width="600" usePlayerDetection="true" useExpressInstall="false" >
  	<mm:flashvar name="javaVersion" value='<%= System.getProperty("java.version") %>' />
	<mm:flashvar name="currentDate" value="<%= new java.util.Date().toString() %>"/>
	<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" >
	    <mx:VBox>
	    <mx:HBox>
	        <mx:Label text="Java version: "/>
	        <mx:Label
                    text="{Application.application.parameters.javaVersion}" fontWeight="bold"/>
	    </mx:HBox>
	    <mx:HBox>
	        <mx:Label text="Current Time: "/>
	        <mx:Label text="{Application.application.parameters.currentDate}"
                    fontWeight="bold"/>
	    </mx:HBox>
	    </mx:VBox>
        </mx:Application>
</mm:mxml>

The following example shows how to invoke an external MXML file while passing dynamic flash variables to it:

<%@ taglib uri="FlexTagLib" prefix="mm" %>

<mm:mxml source="flashvarTest.mxml" width="400" height="200">
  <mm:flashvar name="javaVersion" value='<%= System.getProperty("java.version") %>' />
  <mm:flashvar name="currentDate" value="<%= new java.util.Date().toString() %>"/>
</mm:mxml>
  • Use the <mxml> tag attributes to present a Flex application when the correct version of Flash Player is available or an alternate version of the application when the player is unavailable.

In this example, you enable Flash Player Detection but disable the Express Install. With this configuration, the JSP drops directly to the alternateContentPage instead of proceeding to upgrade Flash Player through Express Install.

<mm:mxml source="FlexApplication.mxml" usePlayerDetection="true"
  useExpressInstall="false" alternateContentPage="MyLegacyApplication.html"/>
Flex 2 Tag Library for JSP Reference

Tag

Description

Attributes

<mxml>

Compiles the MXML code and generates the HTML wrapper. Include MXML source as body content or specify an external source file with the source attribute.

  • source - Location of the MXML code to compile.
  • id - Name used to expose the SWF file through the id or name attribute of the HTML object or embed tag.
  • height - Height of the MXML wrapper.
  • width - Width of the MXML wrapper.
  • useHistoryManagement - Include history management for the Flex application.
  • usePlayerDetection - Include Flash Player detection for the Flex application.
  • useExpressInstall - Install Flash Player through Express Install; ignored if Flash Player detection is disabled.
  • alternateContentPage - Present this alternate page when the Flash Player version is unavailable; ignored if Flash Player detection is disabled.

<flashvar>

Specifies a variable to pass to your Flex Application.

  • name - Specifies the name of the flashvar variable.
  • value - Specifies the value of the flashvar variable.

 

 

How Do I Find Out More?

 

The following sections of the Flex 2 documentation may be helpful in understanding the JSP tag attributes-

AND