Skip to main content

ADF 11g popup and panelwindow: Open wikipedia in a modal popup.

This post was more or less inspired by the noteWindow example on
Oracles tag demo site. When hovering the highlighted text in this example the user gets extra information about the subject. I wanted to give the end user the opportunity to get even more information, for instance by invoking a wikipedia page about the subject. The catch here is that I wanted this information to be shown in a modal popup, and one that is not prohibited by popup blockers. Luckily ADF 11g provides javascript popups that can also be made modal, so the user has to close the popup before returning to the application.

This post describes how I used an in a to open the correct wikipedia in a modal popup.

Step 1: Create the plain text that invokes the noteWindow.

This is taken directly from the mentioned Oracle example.
 <p style="margin-left:30px;width:500px;margin-right:30px;line-height:16px">
Vultures are scavenging birds, feeding mostly on the carcasses of dead animals.
Vultures are found in every continent except
<af:outputText id="antarctica" value="Antarctica"
inlineStyle="color:red; font-weight:bold">
<af:showPopupBehavior popupId="popupAntartica"
triggerType="mouseHover" alignId="antarctica"/>
</af:outputText>
and in Oceania.
</p>

This code produces the following page.



Step 2: Create the noteWindow that calls wikipedia.
This piece of code shows the noteWindow with the extra information. There is an with an associated . Also note the binding of the goLink. This binding makes sure that I can use the textvalue of the goLink in the backing bean to create the URL with the request parameter for the wikipedia page.
<af:popup id="popupAntartica" contentDelivery="lazyUncached">
<af:noteWindow inlineStyle="width:500px;" id="nw2">
<p>Antarctica is Earth's southernmost continent, overlying the South
Pole. It is situated in the southern hemisphere almost entirely
south of the <af:goLink text="Antarctic Circle "
binding="#{toolTips.goLink}"
id="gl1">
<af:showPopupBehavior popupId="popupExt" triggerType="click"/>
</af:goLink> and is surrounded by the Southern
Ocean. At 14.4 million km² (5.4 million sq mi), it is the
fifth-largest continent in area after Asia, Africa, North
America, and South America. Some 98% of Antarctica is covered by
ice, which averages at least 1.6 kilometres (1.0 mi) in thickness.</p>
</af:noteWindow>
</af:popup>

The link in the text is the one that I'm going to use to invoke Wikipedia.



Step 3: Creating the wikipedia URL.

Wikipedia uses a pretty simple URL with request parameters to navigate to the requested subject.
http://en.wikipedia.org/w/index.php?search=<here goes my value>

With this knowledge it is easy to create a URL yourself to navigate to the requested page.
private static String wikipedia =
"http://en.wikipedia.org/w/index.php?search=";

String url;
String reqParam;
private RichGoLink goLink;

public ToolTips() {
}

public String getUrl() {
return wikipedia + this.getReqParam();
}
public void setReqParam(String reqParam) {
this.reqParam = reqParam;
}
public String getReqParam() {
return this.goLink.getText();
}


The popup containing the inlineframe is also straightforward. The source attribute of the inlineframe is an EL expression pointing to the url property in the above code fragment.
<af:popup id="popupExt" animate="default"  >
<af:panelWindow id="pw1"
modal="true"
title="External Internet Info in a Modal Popup"
contentHeight="625"
contentWidth="700"
resize="on">
<af:inlineFrame id="if1" shortDesc="This is an inline frame"
source="#{toolTips.url}"
styleClass="AFStretchWidth"
inlineStyle="height:600px;">
</af:inlineFrame>
</af:panelWindow>
</af:popup>

When you click the goLink, the requested wikipedia page opens in a modal popup.
The users can 'only' return to the application by closing the popup.



Possible extensions to this example.
It is easy and possible to invoke multiple search engines (google, yahoo ....). This example could also be extended by a text box in which the user types a word or sentence which then is forwarded to a search engine. If you know more, don't hesitate to share.
The application used in this blog is available here.

Comments

Lucas Jellema said…
Very nice. Adding that much more information available 'at the fingertips' of the user. In an elegant way.
Sameh Nassar said…
Thank You ... Its really very nice article
Anonymous said…
Thanks for putting this... Very neat...
Unknown said…
That is a cool article. Thanks!!!
Unknown said…
i tried to put the source as http://www.twitter.com and it does not open. Why?
Luc Bors said…
Hi Vik, as far as I know it is twitter policy. In that way you are not able to "embed" twitter in your application. You have to create your own "twitter client" in order to use twitter in your application
Don Kleppinger said…
I had a need to use a frame in a dialog as well and it works but I had one problem in that if you drag the dialog around and the mouse slips into the region while dragging, all the mouse events get routed to the region and it stops dragging, then if you lift the mouse button and move the mouse outside of the region, the dialog is now stuck to the end of the mouse cursor because it lost the mouse up event. To fix this I had to write a mouse event handler and attach it to the iframe that propagates mouse events to the parent page. If you would like a copy of the script let me know

Popular posts from this blog

ADF 12.1.3 : Implementing Default Table Filter Values

In one of my projects I ran into a requirement where the end user needs to be presented with default values in the table filters. This sounds like it is a common requirement, which is easy to implement. However it proved to be not so common, as it is not in the documentation nor are there any Blogpost to be found that talk about this feature. In this blogpost I describe how to implement this. The Use Case Explained Users of the application would typically enter today's date in a table filter in order to get all data that is valid for today. They do this each and every time. In order to facilitate them I want to have the table filter pre-filled with today's date (at the moment of writing July 31st 2015). So whenever the page is displayed, it should display 'today' in the table filter and execute the query accordingly. The problem is to get the value in the filter without the user typing it. Lets first take a look at how the ADF Search and Filters are implemented by...

ADF 11g Quicky 3 : Adding Error, Info and Warning messages

How can we add a message programatically ? Last week I got this question for the second time in a months time. I decided to write a short blogpost on how this works. Adding messages is very easy, you just need to know how it works. You can add a message to your faces context by creating a new FacesMessage. Set the severity (ERROR, WARNING, INFO or FATAL ), set the message text, and if nessecary a message detail. The fragment below shows the code for an ERROR message. 1: public void setMessagesErr(ActionEvent actionEvent) { 2: String msg = "This is a message"; 3: AdfFacesContext adfFacesContext = null; 4: adfFacesContext = AdfFacesContext.getCurrentInstance(); 5: FacesContext ctx = FacesContext.getCurrentInstance(); 6: FacesMessage fm = 7: new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, ""); 8: ctx.addMessage(null, fm); 9: } I created a simple page with a couple of buttons to show the result of setting the message. When the but...

ADF 12c : Using Jasper Reports en JasperSoft Studio 6.1; What Libraries do you need?

Over the last couple of years, or better in the last decade I have implemented several reporting solutions with Jasper Reports in ADF. I did that in ADF 10g, ADF 11.1.1.x, ADF 11.1.2.x and ADF 12.1.x I also used several version of Jasper Reports. There is a whole lot of documentation, blogposts and presentations available. So when today I got a request from one of my customers to make a setup for the implementation of Jasper Reports 6.1 in ADF 12.1.3 I did not expect any problems. Boy was I wrong. Here is the Story With all the knowledge from the past, I decided to follow the known steps. 1) Download iReport Designer, 2) Build a report in iReport 3) Create an ADF application 4) Add the necessary libraries to use the report 5) Call the report from a button via a Managed Bean Step 1 In the past I used iReport designer to build the reports. When you go to the download site of iReport designer you now see an interesting message. So I took this serious and decided not to u...