ADF Faces: The InputTextHyperlink Component

0

Many pages developed with ADF Faces will contain items that represent hyperlinks. The user can enter a URL in such items and submit the value. However, the contents of such an item is not just text: it is potentially a hyperlink. Now would it not be user friendly to allow the user to not only enter the url, but also navigate to it – in a new window to be precise.

For example my demo-page show below allows users to enter requests for books to be ordered for our in-house library. To support their request, they can enter the URL of the Book’s Homepage. I have slightly changed the ADF Faces layout from what normal drag & drop created for the URL field: I have added a little icon (objectImage) that allows navigation to the URL that is in the field itself.

....
 

I will demonstrate very briefly what the code is required for this change: 

&lt;af:panelLabelAndMessage label=&quot;Url&quot;&gt;<br />  &lt;af:panelHorizontal&gt;<br />    &lt;af:inputText autoSubmit=&quot;true&quot;<br />                  id=&quot;NieuweBoekAanvraagUrl&quot;<br />                  value=&quot;#{bindings.NieuweBoekAanvraagUrl.inputValue}&quot;<br />                  required=&quot;#{bindings.NieuweBoekAanvraagUrl.mandatory}&quot;<br />                  rows=&quot;#{bindings.NieuweBoekAanvraagUrl.displayHeight}&quot;<br />                  columns=&quot;40&quot; maximumLength=&quot;250&quot;<br />                  readOnly=&quot;#{!(createModes.CreateNieuweBoekAanvraag)}&quot; /&gt;<br />    &lt;af:goLink targetFrame=&quot;_blank&quot;<br />               partialTriggers=&quot;NieuweBoekAanvraagUrl&quot;<br />               destination=&quot;#{bindings.NieuweBoekAanvraagUrl.inputValue}&quot;&gt;<br />      &lt;af:objectImage source=&quot;/jheadstart/images/hyperlink.jpg&quot;/&gt;<br />    &lt;/af:goLink&gt;<br />  &lt;/af:panelHorizontal&gt;<br />&lt;/af:panelLabelAndMessage&gt; <br />

First of all, my field are all laid out inside a panelForm with two columns. That makes the fields align by prompt (label) and by field. To add a cluster of components (in my case an inputText and a goLink with nested objectImage) and make the cluster align just as nicely, I need to use a panelLabelAndMessage. That element renders a label – aligned with the other labels in the panelForm – and its contents – the panelHorizontal with one or more child components – as the left-aligned field.

The inputText is similar to the one created through drag & drop. Only the autoSubmit property has been set to true. This will cause any change to the URL field to be posted to the server when it occurs. We will see in just a moment how that allows us to have the hyperlink navigate to the correct URL, even if that one has just been typed in by the user.

The objectImage is inside a goLink – which turns the image into a hyperlink. The image itself is something I Googled from the internet. The goLink sends the user to a _blank target-frame, meaning a newly opened (popup) window. The destination attribute of the goLink is set to the value of the URL field – so that is where the new window should lead the user.

Now in order to make sure that the when the user clicks on the hyperlink the navigation is always to the latest value typed in, not just the value retrieved from the database, we have set autoSubmit on the url field to true – to have it posted to the server when it is changed (AJAX style). We also need to instruct the goLink to refresh itself – AJAX style – when the URL has been changed. We do this last bit by adding the Url field’s ID (NieuweBoekAanvraagUrl) to the partialTriggers attribute of the goLink.

Read Only Items

This same page can be rendered in read-only mode. If that is the case, we want to display the URL field in a slightly different way:

 

Here we do not show the actual URL value. Instead, we have an hyperlink that shows the title of the book and links to the location specified by the contents of the Url item. Again we have used the panelLabelAndMessage to lay out the items.

&lt;af:panelLabelAndMessage label=&quot;Url&quot;                         <br />                         rendered=&quot;#{!(bindings.NieuweBoekAanvraagUrl.inputValue == null)&quot;&gt;<br />  &lt;af:panelHorizontal&gt;<br />    &lt;h:outputLink styleClass=&quot;xa&quot;    <br />                  target=&quot;_blank&quot; <br />                  value=&quot;#{bindings.NieuweBoekAanvraagUrl.inputValue}&quot; &gt;<br />      &lt;h:outputText value=&quot;#{bindings.NieuweBoekAanvraagTitel}&quot;  /&gt; <br />    &lt;/h:outputLink&gt;<br />  &lt;/af:panelHorizontal&gt;<br />&lt;/af:panelLabelAndMessage&gt;<br />&nbsp;

There is no real reason for using the h:outputLink here instead of the goLink. Previously I needed the goLink as it supports the AJAX style partial page refresh – the partialTriggers attribute – but since this page is read only, I do not need that facility and may use the simple outputLink.

Share.

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PLSQL), Service Oriented Architecture, BPM, ADF, Java in various shapes and forms and many other things. Author of the Oracle Press book: Oracle SOA Suite 11g Handbook. Frequent presenter on conferences such as JavaOne, Oracle OpenWorld, ODTUG Kaleidoscope, Devoxx and OBUG. Presenter for Oracle University Celebrity specials.

Comments are closed.