You are receiving this e-mail because you elected to receive e-mail from Sun Microsystems, Inc. To update your communications preferences, please see the link at the bottom of this message. We respect your privacy and post our privacy policy prominently on our Web site http://sun.com/privacy/ Please do not reply to the mailed version of the newsletter, this alias is not monitored. Feedback options are listed in the footer for both content and delivery issues. |
February 2006 | | |||
Sun Developer Network NEWSLETTER | ||||
The Sun Developer Network Program Newsletter is a monthly email informing developers of the latest news, resources, programs, and events available through the Sun Developer Network. |
|
|
Comments and Contact Information: For technical assistance about Newsletter delivery, broken links, or subscribe/unsubscribe help, fill out the web form. Write to us at: SDN Editorial Team, MS: UMPK18-113, 18 Network Circle, Menlo Park, CA 94025, USA IMPORTANT: Please read our Licensing, Terms of Use, and Privacy policies: http://developer.java.sun.com/berkeley_license.html http://www.sun.com/share/text/termsofuse.html Privacy Statement: Sun respects your online time and privacy (http://sun.com/privacy). You have received this based on your email preferences. If you would prefer not to receive this information, please follow the steps at the bottom of this message to unsubscribe. © 2006 Sun Microsystems, Inc. All Rights Reserved. For information on Sun's trademarks see: http://sun.com/suntrademarks Java, J2EE, J2SE, J2ME, and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Sun Microsystems, Inc. 10 Network Circle, MPK10-209 Menlo Park, CA 94025 US This service may provide, or third parties may provide, links to other Internet sites or resources. Because Sun has no control over such sites and resources, you acknowledge and agree that Sun is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource. |
Please unsubscribe me from this newsletter. |
You are receiving this e-mail because you elected to receive e-mail from Sun Microsystems, Inc. To update your communications preferences, please see the link at the bottom of this message. We respect your privacy and post our privacy policy prominently on our Web site http://sun.com/privacy/ Please do not reply to the mailed version of the newsletter, this alias is not monitored. Feedback options are listed in the footer for both content and delivery issues. |
February 27, 2006 | | ||
Enterprise Java Technologies NEWSLETTER | |||
Welcome to the Enterprise Java Technologies Newsletter. Here you'll find links to the latest products, tools, resources, and events relating to development with the Java Platform, Enterprise Edition (Java EE, formerly known as J2EE). |
|
|
Comments and Contact Information: There are three ways to send your feedback about the Enterprise Java Technologies Newsletter: For comment about the content of this newsletter, fill out the Rate and Review form, above. For technical assistance about Newsletter delivery, broken links, or subscribe/unsubscribe help, fill out the web form. Write to us at: SDN Editorial Team, MS: UMPK18-113, 18 Network Circle, Menlo Park, CA 94025, USA Subscribe/Unsubscribe: Subscribe to other Java technology newsletters:
- To subscribe, visit the SDN Newsletters and Publications page, select the newsletters you want to subscribe to and click "Update." - To unsubscribe, go to the subscriptions page, uncheck the appropriate checkbox, and click "Update." IMPORTANT: Please read our Licensing, Terms of Use, and Privacy policies: http://developer.java.sun.com/berkeley_license.html http://www.sun.com/share/text/termsofuse.html Privacy Statement: Sun respects your online time and privacy (http://sun.com/privacy). You have received this based on your email preferences. If you would prefer not to receive this information, please follow the steps at the bottom of this message to unsubscribe. Archives: You'll find the Enterprise Java Technologies Newsletter archives at: http://java.sun.com/developer/techDocs/Newsletters/jdc_newsletters.html © 2006 Sun Microsystems, Inc. All Rights Reserved. For information on Sun's trademarks see: http://sun.com/suntrademarks Java, J2EE, J2SE, J2ME, and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Sun Microsystems, Inc. 10 Network Circle, MPK10-209 Menlo Park, CA 94025 US |
Please unsubscribe me from this newsletter. |
You are receiving this e-mail because you elected to receive e-mail from Sun Microsystems, Inc. To update your communications preferences, please see the link at the bottom of this message. We respect your privacy and post our privacy policy prominently on our Web site http://sun.com/privacy/ Please do not reply to the mailed version of the newsletter, this alias is not monitored. Feedback options are listed in the footer for both content and delivery issues. |
| ||||||
In this Issue | ||
Welcome to the Enterprise Java Technologies Tech Tips for February 25, 2006. Here you'll get tips on using enterprise Java technologies and APIs, such as those in Java 2 Platform, Enterprise Edition (J2EE) and Java Platform, Enterprise Edition (Java EE). This issue covers: » Using AJAX With Non-HTML Markup in JSF » Accessing a Secure Enterprise Bean From a Java Client or Through Java Web Start Technology These tips were developed using an open source reference implementation of Java EE 5 called GlassFish. You can download GlassFish from the GlassFish Community Downloads page. You can download the sample archive for the tip Using AJAX With Non-HTML Markup in JSF. There are two sample archives for the tip "Accessing a Secure Enterprise Bean From a Java Client". One is for a standalone client example, the other is for a Java Web Start example. You can download the archive for the Java Web Start example. You can download the archive for the standalone client example. Any use of this code and/or information below is subject to the license terms. See the Subscribe/Unsubscribe note at the end of this newsletter to subscribe to Tech Tips that focus on technologies and products in other Java platforms. | ||
USING AJAX WITH NON-HTML MARKUP IN JSF | ||
by Roger Kitain JavaServer Faces (JSF) technology is a framework that simplifies building user interfaces for Java EE and J2EE applications. The March 24, 2004 Tech Tip, Introducing JavaServer Faces Technology gave a brief overview of the technology. It also showed how to create a JSF application that includes GUI components that are modeled by the JSF framework. A later tip showed how to create custom components with JavaServer Faces technology. Since the publishing of those tips, the technology has gone to the 1.2 level. One of the new features in JSF 1.2 is the ability to support multiple render kits in a single JSF application. In JSF, render kits are used to present the user interface in a markup such as HTML. JSF comes with an HTML render kit, but you could write a render kit to display user interface components in other markup languages such as Scalable Vector Graphics (SVG) or XML User Interface Language (XUL). You might want to take advantage of the strengths that each markup language provides by combining them in a single JSF application. For example, you can use SVG to create sophisticated graphics and animations for an application. However SVG does not have a widget set which includes buttons or other components. You have to create these widgets using a markup. In contrast, XUL has a complete set of user interface controls that can easily be used, but it lacks the graphical capabilities that SVG provides. Common to both of these markups is the lack of a built-in form submission mechanism like the one available in HTML. However Asynchronous JavaScript and XML (AJAX) can be used with some JSF 1.2 features to effectively produce form submissions from non-HTML markup. In this tip you'll see a demonstration that uses AJAX and three render kits (HTML, SVG, and XUL) in a JSF application. (For more information about AJAX see the November 22, 2005 Tech Tip, Using AJAX with Java Technology.) JSF Life Cycle Example User interactions with a JSF application are processed in a series of steps known as the "JSF life cycle". Typically the life cycle is illustrated as a set of connected boxes, with each box identifying a phase in the process. Lines with arrows show the flow from one phase to the next. Accompanying this tip is an example JSF application that displays an animated version of the JSF life cycle. As mentioned earlier, the application uses the HTML, SVG and XUL render kits. The following diagram shows the flow of the demo between the pages of different markup:
The application begins with the display of an HTML page that gives some background and design details pertinent to the demonstration.
This page is produced with the standard HTML render kit. If you click the Next button at the bottom of the page it displays an SVG page that is rendered with an SVG render kit. The SVG page graphically illustrates the JSF life cycle.
If you click on any box that represents a life cycle phase (such as Restore View Phase), it uses AJAX to generate a form submission. In response, you should see an XUL page that displays more detail about that JSF life cycle phase.
Below the JSF life cycle illustration is a larger box that contains various buttons with labels such as Initial Request and Validation Error. If you click on these buttons you'll see an animated display of a specific process flow through the life cycle phases (for instance, the process flow for handling an initial request).
Let's take a look at some of the code for the demonstration. Posting From The Client First, let's examine the SVG page. Here is a snippet of the SVG page written with JSF tags: <%@ page contentType="image/svg+xml"%> <%@ taglib uri="http://java.sun.com/jsf/svg" prefix="g" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> ... <f:view renderKitId="SVG" > <g:form id="form"> ... <g:commandButton id="restore" width="120" height="50" x="100" y="100" type="submit" action="xul-restore" style="stroke:black; fill:#8470ff;" > <g:outputText x="130" y="120" textAnchor="middle" value="Restore" /> <g:outputText x="135" y="140" textAnchor="middle" value="View" /> </g:commandButton> ... </g:form> </f:view> Notice the page directive that indicates the content type of the page: <%@ page contentType="image/svg+xml"%> and the tag that indicates that SVG is the rendering technology for the page: <f:view renderKitId="SVG" > You can learn more about the directives, tags, and attributes that need to appear on a page that uses a render kit such as SVG, in the article Creating and Using a Custom Render Kit. In response to the information on the SVG page, the SVG render kit on the server produces the following SVG markup: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> ... <script xlink:href="/jsf-renderkits/src/script/http-svg.es"> </script> <script xlink:href="/jsf-renderkits/src/script/lifecycle.es"> </script> <g id="form" method="post" action="/jsf-renderkits/render/svg.jsp"> ... <g id="form:restore" onclick="form_post(evt)"> <rect width="120" height="50" x="100" y="100" style="stroke:black; fill:#8470ff;"></rect> <text x="100" y="150" text-anchor="middle"></text> <text x="130" y="120">Restore</text> <text x="135" y="140">View</text> </g> ... <text name="javax.faces.ViewState" id="javax.faces.ViewState" value="_id4:_id6" visibility="hidden">_id4:_id6</text> <text name="javax.faces.RenderKitId" id="javax.faces.RenderKitId" value="SVG" visibility="hidden">SVG</text> </g> <script><![CDATA[ function form_post(evt) { var control = evt.target; var form = getForm(control); var postData = getPostData(form, control); var url = "/jsf-renderkits/render/svg.jsp"; sendRequest(url, postData); } //]]> </script> </svg> This code is produced by various renderers in the SVG render kit. The <script xlink:href="/jsf-renderkits/src/script/http-svg.es"> </script> <script xlink:href="/jsf-renderkits/src/script/lifecycle.es"> </script> and also the starting "form" group: <g id="form" method="post" action="/jsf-renderkits/render/svg.jsp"> The The <g id="form:restore" onclick="form_post(evt)"> <rect width="120" height="50" x="100" y="100" style="stroke:black; fill:#8470ff;"></rect> <text x="100" y="150" text-anchor="middle"></text> <text x="130" y="120">Restore</text> <text x="135" y="140">View</text> </g> Note that the public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ... UIComponent root = context.getViewRoot(); UIComponent myForm = component; while (!(myForm instanceof UIForm) && root != myForm) { myForm = myForm.getParent(); } String formMethodName = myForm.getClientId(context) + "_post(evt)"; writer.writeAttribute( "onclick", formMethodName, "onclick"); The <text name="javax.faces.ViewState" id="javax.faces.ViewState" value="_id4:_id6" visibility="hidden">_id4:_id6</text> <text name="javax.faces.RenderKitId" id="javax.faces.RenderKitId" value="SVG" visibility="hidden">SVG</text> </g> It also produces the JavaScript function that will collect the post data and send the request: <script><![CDATA[ function form_post(evt) { var control = evt.target; var form = getForm(control); var postData = getPostData(form, control); var url = "/jsf-renderkits/render/svg.jsp"; sendRequest(url, postData); } //]]> </script> The mapping is such that the request goes to the JSF controller. The functions function getPostData(form, control) { var formValues = new Array(); formValues[0] = new Object(); formValues[0].id = control.parentNode.id; formValues[0].value = control.parentNode.id; formValues[1] = new Object(); formValues[1].id = form.id; formValues[1].value = form.id; ... var postData = ""; for (var i=0; i<formValues.length; i++) { if (formValues[i].id == "javax.faces.ViewState") { var re = new RegExp("\\+", "g"); var val = formValues[i].value; formValues[i].value = val.replace(re, "\%2B"); } postData += formValues[i].id + "=" + formValues[i].value; if (i != formValues.length-1) { postData += "&"; } } return postData; } Notice that Processing the Request When the request is sent to JSF, it goes through the normal JSF life cycle processing steps. However, there is a special JSF phase listener registered to execute after the invoke applications phase (that is, just before the render response phase). If the request is an AJAX request (denoted by the XML-HTTP string in the request header), this phase listener will get the view identifier of the view that will be rendered next. The phase listener then puts the view identifier in the response header. public class ResponsePhaseListener implements PhaseListener { private static final String XML_HTTP = "XML-HTTP"; private static final String VIEW_URI = "VIEW-URI"; ... public void afterPhase(PhaseEvent event) { // Disregard requests that are not XMLHttpRequest(s) Map<String, String> requestHeaderMap = event.getFacesContext().getExternalContext(). getRequestHeaderMap(); if (requestHeaderMap.get(XML_HTTP) == null) { return; } // If we're dealing with an XMLHttpRequest... // Get the URI and stuff it in the response header. FacesContext context = event.getFacesContext(); String viewId = context.getViewRoot().getViewId(); String actionURL = context.getApplication().getViewHandler() .getActionURL(context, viewId); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setHeader("Cache-Control", "no-cache"); response.setHeader(VIEW_URI, actionURL); } ... } The function processResponse() { var request = getXMLHttpRequest(); if (request.readyState == 4) { if (request.status == 200) { var action = request.getResponseHeader("VIEW-URI"); window.location.href = action; return; } } } For more information using render kits in JSF, see the technical article Creating and Using a Custom Render Kit. Running the Sample Code A sample package accompanies this tip that demonstrates the techniques covered in the tip. You can deploy the sample package on any web container that supports the Servlet 2.5 API, JavaServer Pages (JSP) Technology 2.1, and JSF 1.2. You will also need to use JDK 5. For the client (browser) you need to use a Mozilla browser with built-in SVG support, such as Firefox 1.5. To install and run the sample:
About the Author Roger Kitain is the JavaServer Faces co-specification lead. He has been extensively involved with server-side web technologies and products since 1997. Roger started working on JavaServer Faces technology in 2001, as a member of the reference implementation team. He has experience with Servlet and JSP technologies. Most recently, Roger has been involved with different rendering technologies for JSF. Back to Top | ||
ACCESSING A SECURE ENTERPRISE BEAN FROM A JAVA CLIENT OR THROUGH JAVA WEB START TECHNOLOGY | ||
by Sreenivas Munnangi This Tech Tip shows you how to access a secure Enterprise JavaBeans component (also called an "enterprise bean") from a standalone Java client and from a Java EE application client that uses Java Web Start technology. The tip presents examples that show these clients accessing a secure Management Enterprise JavaBean (MEJB) that conforms to the J2EE Management specification, JSR 77. The J2EE Management specification provides a standard management model for exposing and accessing management information, operations, and attributes for J2EE components. An MEJB provides interoperable remote access to the model from any standard J2EE application. The tip assumes that you are using either the Sun Java System Application Server 8.x or a GlassFish build. You can download Sun Java Application Server 8.2 or 8.1 as part of the J2EE 1.4 SDK from the J2EE 1.4 Downloads page. GlassFish is an open source Java EE-based application server. You can download GlassFish from the GlassFish Community Downloads page. Securing an Enterprise Bean Security for J2EE application components such as enterprise beans is provided by their containers. A container provides two kinds of security: declarative and programmatic. Declarative security expresses an application's security structure, including security roles, access control, and authentication requirements, in a form external to the application (that is, in a deployment descriptor). Programmatic security is embedded in an application and is used to make security decisions. Programmatic security is useful when declarative security alone is not sufficient to express the security model of an application. The mechanics of providing declarative security for these resources involve mapping in a deployment descriptor individual user identities or groups of user identities to a role, that is, an abstract name for the permission to access a particular set of resources in an application. For example, the following elements in the Sun Java Application Server deployment descriptor, <security-role-mapping> <role-name>admin-role</role-name> <group-name>asadmin</group-name> </security-role-mapping> In addition, application servers such as Sun Java System Application Server 8.x or GlassFish provide a way to associate groups while creating a principal (that is, an individual user identity that can be authenticated). This is done through the asadmin create-file-user --port <port> --host <host> --user <user-id> --passwordfile <passwordfile-location> --authrealmname admin-realm --groups <admingrp> <realm-user-id> After the mapping is in place, the container can determine if a user has the needed permission to access a protected resource such as a secure enterprise bean. For standalone clients, declarative security is insufficient to communicate with a secure enterprise bean. Instead you need to provide programmatic security. Programmatic Security for a Secure Enterprise Bean Programmatic security for a standalone client requires an API that provides programmatic login for the client. The Sun Java System Application Server 8.x and GlassFish provide this API through the class public Boolean login(String user, String password); The Let's look at an example of programmatic security for a secure enterprise bean. Accompanying this tip is a package that contains the code for a standalone client that accesses a secure MEJB. Here's a code snippet taken from the standalone client code: ProgrammaticLogin pm = new ProgrammaticLogin(); pm.login(userId, password); Context initial = new InitialContext(); Object objref = initial.lookup("ejb/mgmt/MEJB"); ManagementHome home = (ManagementHome)PortableRemoteObject.narrow( objref, ManagementHome.class); Management mejb = home.create(); String domain = mejb.getDefaultDomain(); The code first instantiates You might ask how are the user's credentials processed? The user credentials are passed to the server when the client calls the enterprise bean's method. The method call is intercepted by the IIOP/ORB infrastructure and the credentials are stored in the security context. If the method being invoked needs permission, the EJB container retrieves the user credentials from the security context and validates them. If the credentials are not valid, the method throws a security exception. After the lookup and narrow methods succeed, a reference to the Now it's time to try the sample applications. The samples require you to have access to ant or asant that is included in GlassFish and Sun Java Application Server 8.1 or 8.2. Running the Standalone Client Example The standalone client works directly with a predeployed system application. To install and run the standalone client example:
Running the Java Web Start Technology Example This example uses a Java EE application client that will be deployed to the application server. As is the case for the previous example, this example uses GlassFish. This example has been tested to work with JDK 5.0 or JRE 5.0 only. To install and run the example:
About the Author Sreenivas Munnangi is a senior member of the Sun Java Application Server Administration and Management team. He has worked in the J2EE group for the last three years. He was a key contributor to the Application Server Enterprise Edition design and implementation. His earlier experience was in the areas of eCommerce applications, web applications, and N-tier application architecture. Back to Top | ||
GET THE PREVIEW OF THE JAVA EE 5 SDK! | ||
On February 21, 2006, Sun announced availability of the preview of Java EE 5 SDK, which includes Application Server Platform Edition 9 beta. This release is a simultaneous release with NetBeans Enterprise Pack 5.5, providing developers with the next generation Java platform and tools for building and deploying enterprise Java and Service-Oriented Architecture (SOA)-ready applications to solve business challenges. Sun led the development of these breakthrough technologies, incorporating key contributions from the open source GlassFish Project and NetBeans.org communities to create an innovative, robust, and scalable development platform that is ideal for enterprise Web 2.0 development. Back to Top | ||
Comments? Send your feedback on the Tech Tips: http://developers.sun.com/contact/feedback.jsp?category=newslet Subscribe to the following newsletters for the latest information about technologies and products in other Java platforms:
IMPORTANT: Please read our Terms of Use, Privacy, and Licensing policies: http://www.sun.com/share/text/termsofuse.html http://www.sun.com/privacy/ http://developer.java.sun.com/berkeley_license.html ARCHIVES: You'll find the Enterprise Java Technologies Tech Tips archives at: http://java.sun.com/developer/EJTechTips/index.html © 2006 Sun Microsystems, Inc. All Rights Reserved. For information on Sun's trademarks see: http://sun.com/suntrademarks Java, J2EE, J2SE, J2ME, and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. |
Please unsubscribe me from this newsletter. |
Born on shraavana shudha chauthi of dundubhi naama samvaswara, Im kiran alias kini alias kiri bought up by loving parents. Being from agricultural family I have learnt plowing, carting but never learnt climbing trees. Now away from home I have lost touch with the agricultural skills.