<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2350921891890633179</id><updated>2011-11-05T15:57:05.379+05:30</updated><category term='Modal Panel'/><category term='Ajax'/><category term='Rich Faces'/><category term='Dialog'/><title type='text'>Technology Bytes</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://smtechbytes.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2350921891890633179/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://smtechbytes.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Deepu Joseph</name><uri>http://www.blogger.com/profile/08403019462823853350</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2350921891890633179.post-5206205417408459838</id><published>2009-04-06T09:34:00.000+05:30</published><updated>2009-04-06T09:36:44.295+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Modal Panel'/><category scheme='http://www.blogger.com/atom/ns#' term='Dialog'/><category scheme='http://www.blogger.com/atom/ns#' term='Rich Faces'/><title type='text'>Richfaces ModalPanel in Internet Explorer</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt;RichFaces provides ready-to-use Ajax components to enable building Ajax-based JSF applications.&lt;/span&gt;&lt;span style="font-size: 14pt; "&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt;One of the interesting component that you will end up commonly end up relying on would be the rich:modalPanel. Modal Panel, as the name implies, lets you display a modal dialog window (desktop borrowed paradigm) on screen that will render the parent widow locked out for edit. &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt;You may refer to the Richfaces developer documentation for more details of the usage of this component. Although Richfaces library does a good job in handling the browser incompatibility concerns, there are times when it fails to find a good solution. Modal Panel is such a special case; as per the Practical Richfaces book, in order to avoid a bug in Internet Explorer, the root node of the modal panel is moved to the top of a DOM tree.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt;However, you should have a separate &lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt;form&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt; inside the modal panel if you want to perform submits from this panel. So the modal panel itself should not be placed inside any other form if it has its own form.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span"  style="font-family:'lucida grande';"&gt;If you have multiple Modal Panels in your application, you may use the “zindex” property for relative positioning of the windows (default value is 100)&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2350921891890633179-5206205417408459838?l=smtechbytes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://smtechbytes.blogspot.com/feeds/5206205417408459838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://smtechbytes.blogspot.com/2009/04/richfaces-modalpanel-in-internet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2350921891890633179/posts/default/5206205417408459838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2350921891890633179/posts/default/5206205417408459838'/><link rel='alternate' type='text/html' href='http://smtechbytes.blogspot.com/2009/04/richfaces-modalpanel-in-internet.html' title='Richfaces ModalPanel in Internet Explorer'/><author><name>Ranjan Kumar</name><uri>http://www.blogger.com/profile/01711605915140276605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_Mq7jvfMo_5o/TB2qCMYRc3I/AAAAAAAABCI/BsuPIkT8iRU/S220/22102008.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2350921891890633179.post-7590099680673869489</id><published>2009-04-04T14:56:00.003+05:30</published><updated>2009-04-04T15:14:27.569+05:30</updated><title type='text'>JAXB, Annotated beans and Unmarshallar Listener</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;JAXB is a cool revelation from the Java Technology Platform that offers enough goodies off the shelf for processing simple to complex xml structures. Auto-code generation for creation of marshalling and un-marshalling stubs that happens under the hood has been one of the much hyped about feature of JAXB used by a fairly large percentage of the Java community. And then, there are people like me who like to have a much better control of what is going on behind the scenes. JAXB won’t disappoint you if you are that kind of a breed who wants to write every piece of code and don’t want any junk coming from code generation tools.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;In this post, we will look at how JAXB can be used in conjunction with Java 5 Annotations to avoid code generation for un-marshalling operations. We will also explore how JAXB listeners can be used for processing complex xml structures when building your custom Java structures in one pass along with the un-marshalling operation.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Preparing Annotated Beans&lt;/strong&gt;&lt;br /&gt;JAXB provides you various alternatives to un-marshal xml using Annotations. In this post, we will use setters and getters of the annotated beans. First, let us prepare the bean for the root node:&lt;br /&gt;Let us say, the xml to be unmarchalled looks like this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;pre style="BORDER-BOTTOM: #999999 1px dashed; BORDER-LEFT: #999999 1px dashed; PADDING-BOTTOM: 5px; LINE-HEIGHT: 14px; BACKGROUND-COLOR: #eee; PADDING-LEFT: 5px; WIDTH: 100%; PADDING-RIGHT: 5px; FONT-FAMILY: Andale Mono, Lucida Console, Monaco, fixed, monospace; COLOR: #000000; FONT-SIZE: 12px; OVERFLOW: auto; BORDER-TOP: #999999 1px dashed; BORDER-RIGHT: #999999 1px dashed; PADDING-TOP: 5px"&gt;&lt;code&gt;&amp;lt;MyXmlRoot name="My Root"&amp;gt;&lt;br /&gt;     ...&lt;br /&gt;&amp;lt;/MyXmlRoot&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The root tag of the xml as in the example above is &lt;&gt;&lt;br /&gt;The annotated bean will look like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="BORDER-BOTTOM: #999999 1px dashed; BORDER-LEFT: #999999 1px dashed; PADDING-BOTTOM: 5px; LINE-HEIGHT: 14px; BACKGROUND-COLOR: #eee; PADDING-LEFT: 5px; WIDTH: 100%; PADDING-RIGHT: 5px; FONT-FAMILY: Andale Mono, Lucida Console, Monaco, fixed, monospace; COLOR: #000000; FONT-SIZE: 12px; OVERFLOW: auto; BORDER-TOP: #999999 1px dashed; BORDER-RIGHT: #999999 1px dashed; PADDING-TOP: 5px"&gt;&lt;code&gt;import javax.xml.bind.annotation.XmlAccessType;&lt;br /&gt;import javax.xml.bind.annotation.XmlAccessorType;&lt;br /&gt;import javax.xml.bind.annotation.XmlAttribute;&lt;br /&gt;import javax.xml.bind.annotation.XmlRootElement;&lt;br /&gt;&lt;br /&gt;@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)&lt;br /&gt;@XmlRootElement(name = "MyXmlRoot")&lt;br /&gt;public class MyXmlRoot {&lt;br /&gt;   &lt;br /&gt;    private String name;&lt;br /&gt;   &lt;br /&gt;    public String getName() {&lt;br /&gt;        return name;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    @XmlAttribute(name = "name")&lt;br /&gt;    public void setName(String name) {&lt;br /&gt;        this.name = name;&lt;br /&gt;      &amp;lt;add your custom code here&amp;gt;   &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I have included the imports to make your life easy. The first annotation @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) instructs JAXB to invoke setters of the annotated beans when encountering any of the attributes. Please refer JAXB documentation for the other types of accessors supported. By using the setters, you get a chance to plug-in your custom handler code.&lt;br /&gt;&lt;br /&gt;Second annotation @XmlRootElement(name = "MyXmlRoot") tells JAXB to use this bean un-marshalling the root Xml tag (MyXmlRoot)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Introducing a Listener&lt;/strong&gt;&lt;br /&gt;To create a custom listener, extend your class from Unmarshaller.Listener and override the afterUnmarshall method as shown below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="BORDER-BOTTOM: #999999 1px dashed; BORDER-LEFT: #999999 1px dashed; PADDING-BOTTOM: 5px; LINE-HEIGHT: 14px; BACKGROUND-COLOR: #eee; PADDING-LEFT: 5px; WIDTH: 100%; PADDING-RIGHT: 5px; FONT-FAMILY: Andale Mono, Lucida Console, Monaco, fixed, monospace; COLOR: #000000; FONT-SIZE: 12px; OVERFLOW: auto; BORDER-TOP: #999999 1px dashed; BORDER-RIGHT: #999999 1px dashed; PADDING-TOP: 5px"&gt;&lt;code&gt;public class UnmarshallerListener extends Unmarshaller.Listener {&lt;br /&gt;    @Override&lt;br /&gt;    public void afterUnmarshal(Object target, Object parent) {&lt;br /&gt;    super.afterUnmarshal(target, parent);&lt;br /&gt;    &amp;lt;add your custom code here&amp;gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This method gives you an opportunity to inject additional processing code after the target node has been un-marshalled.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Careful with JAXB Context&lt;br /&gt;&lt;/strong&gt;Once you are all set with the annotated beans, listeners and custom java structures, it is time for improvisation. Performance is an important aspect that you may want to keep an eye on. On time-slicing the different operations, I found that the time elapsed in creating a JAXB Context has the maximum performance overhead. A smart fix would be to create a single context instance and re-use the same for each of the un-marshaller operations. Follow this approach when you have several XMLs to be un-marshaled over a period of time.&lt;br /&gt;&lt;br /&gt;&lt;pre style="BORDER-BOTTOM: #999999 1px dashed; BORDER-LEFT: #999999 1px dashed; PADDING-BOTTOM: 5px; LINE-HEIGHT: 14px; BACKGROUND-COLOR: #eee; PADDING-LEFT: 5px; WIDTH: 100%; PADDING-RIGHT: 5px; FONT-FAMILY: Andale Mono, Lucida Console, Monaco, fixed, monospace; COLOR: #000000; FONT-SIZE: 12px; OVERFLOW: auto; BORDER-TOP: #999999 1px dashed; BORDER-RIGHT: #999999 1px dashed; PADDING-TOP: 5px"&gt;&lt;code&gt;public class MyUnmarshaller {&lt;br /&gt;    private static MyUnmarshaller instance;&lt;br /&gt;    private JAXBContext context;&lt;br /&gt;    private MyXmlRoot root;&lt;br /&gt;   &lt;br /&gt;    private MyUnmarshaller() {&lt;br /&gt;        try {&lt;br /&gt;            if(context == null)&lt;br /&gt;                context = JAXBContext.newInstance(MyXmlRoot.class);&lt;br /&gt;        } catch (JAXBException e) {&lt;br /&gt;            throw new RuntimeException(e);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public static MyUnmarshaller getInstance() {&lt;br /&gt;        if(instance == null) {&lt;br /&gt;            instance = new MyUnmarshaller();&lt;br /&gt;        }&lt;br /&gt;        UnmarshallarContext.createNewInstance();&lt;br /&gt;        return instance;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Code snippet above shows several best practices. There is only one instance of the xml un-marshallar. When the instance is created, it also creates a single instance of the JAXB Context. This way although the first un-marshaller operation is costly, from the second operation onwards, the same JAXB context can be re-used resulting in better performance.&lt;br /&gt;You will also observe creation of an UnmarshallarContext. This context may be used to share the context sensitive information across the complete stages of processing xml document.&lt;br /&gt;Final Step&lt;br /&gt;We are all set to run the Unmarshallar. Here is a simplified code snippet that takes in the InputStream of the xml and performing the Unmarshallar operation.&lt;br /&gt;&lt;br /&gt;&lt;pre style="BORDER-BOTTOM: #999999 1px dashed; BORDER-LEFT: #999999 1px dashed; PADDING-BOTTOM: 5px; LINE-HEIGHT: 14px; BACKGROUND-COLOR: #eee; PADDING-LEFT: 5px; WIDTH: 100%; PADDING-RIGHT: 5px; FONT-FAMILY: Andale Mono, Lucida Console, Monaco, fixed, monospace; COLOR: #000000; FONT-SIZE: 12px; OVERFLOW: auto; BORDER-TOP: #999999 1px dashed; BORDER-RIGHT: #999999 1px dashed; PADDING-TOP: 5px"&gt;&lt;code&gt;public void unmarshal(InputStream stream) {       &lt;br /&gt;try {&lt;br /&gt;        Unmarshaller unmarshaller = context.createUnmarshaller();&lt;br /&gt;        UnmarshallerListener listener = new UnmarshallerListener();&lt;br /&gt;        unmarshaller.setListener(listener);&lt;br /&gt;        root = (MyXmlRoot) unmarshaller.unmarshal(new InputSource(stream));&lt;br /&gt;    } catch (JAXBException e) {&lt;br /&gt;        throw new RuntimeException(e);&lt;br /&gt;    }       &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Please feel free to use the code in your applications and let us know if you liked it. Any inputs or techniques to improve the code are most welcome.&lt;br /&gt;Email us at &lt;/span&gt;&lt;a href="mailto:smtechbytes@gmail.com"&gt;&lt;span style="font-family:trebuchet ms;"&gt;smtechbytes@gmail.com&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; if you need the full source code.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2350921891890633179-7590099680673869489?l=smtechbytes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://smtechbytes.blogspot.com/feeds/7590099680673869489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://smtechbytes.blogspot.com/2009/04/jaxb-annotated-beans-and-unmarshallar.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2350921891890633179/posts/default/7590099680673869489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2350921891890633179/posts/default/7590099680673869489'/><link rel='alternate' type='text/html' href='http://smtechbytes.blogspot.com/2009/04/jaxb-annotated-beans-and-unmarshallar.html' title='JAXB, Annotated beans and Unmarshallar Listener'/><author><name>Radhesh</name><uri>http://www.blogger.com/profile/12238361656502585971</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/_cO574zBMx9Q/SMLEpmy3VlI/AAAAAAAAAUI/bCMgFtzGzpc/S220/PB240006.JPG'/></author><thr:total>0</thr:total></entry></feed>
