Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Problem


There is a common problem with displaying rich-formatted text using WebDynpro. This issue arise many times on Web Dynpro Java.



Also upcoming WebDynpro for ABAP offers FormattedTextView UI element that should solve the problem, WebDynpro for Java still lacking such functionality. Even newer builds of NW04s, that are featuring many brand new and greatly enhanced UI controls (superb Table, TriStateCheckBox, ItemListBox etc), still do not contain formatted text view.</p>


A bit of history :wink:



Certain time ago I were developing some kind of serializer, that converts node structure to XML. As a mere mortal, I did several errors. But one error grabbed my attention.



To unify serialization process and write as less code as possible (very nice motto, believe me :wink: I delegated value-to-string conversion process to corresponding instance of ISimpleType (getSimpleType() on node attribute). However, instead of correct toString(value) form (which is locale-agnostic and hence ideal for persisting data) I used format(value). Only later I get to know that "format" serves for UI rendering purposes.



Thanks God, I added attribute of type binary to context. And I was very surprised when I checked result XML: there was an URL! However I hadn’t supply anything like URL in node elements!</p>


Solution (first probe)


Quick analysis gave an answer: URL was "serialized" form of binary attribute! So I forgot about serialization and quickly prototyped a sample application that does that trick with "RTF" display:

  • Create an attribute of type binary

  • Save it into some instance field of controller

  • Convert HTML source into array of bytes

  • Using binary type, convert bytes array into URL

  • Use IFrame UI control to display this URL





See Re: display already formatted text for more detailed description and code. Also the code is available with sample project, just uncomment "/* old */" sections.</p>


Problems


I have tested this code with several versions of NW04 and several browsers. Everything works as expected. However, some people sent me a feedback, that instead of displaying HTML inline in frame, browser starts "Save as..." dialog. Even when I sent complete workable application, the issue on their side persists.



The other problem I faced when try to run this application on NW04s. It works just fine for first time. But when I try to alter HTML source and apply it for second time, the whole application ends with message about expiration.


Solution (second and current, but not final)


I need an alternative for ad-hoc usage of ISimpleType functionality. Obviously, they do not work any longer, and no one promised that they will. The obvious "legal" choice is a binary cache, accessible via combo of WDWebResource / IWDCachedWebResource. And, it makes the solution work again:





final String formattedStr = wdContext
.currentContextElement()
.getRtf();
try
{
final String html = formattedStr;
final IWDCachedWebResource resource = WDWebResource.getWebResource
(
formattedStr.getBytes("UTF-8"),
WDWebResourceType.HTML
);
resource.setResourceName("HTML_inline.html");
resource.setAttachement( false );
resource.setReadOnce( false );
wdContext.currentContextElement().setUrl
(
resource.getAbsoluteURL()
);
}
catch (final Exception ex)
{
wdComponentAPI.getMessageManager()
.reportException( new WDNonFatalException(ex), false );
}



Sample, issues and “what’s next?”


Here is a screen-shop of running application:


image
You may download sample project file here (rename to *.zip after downloading)</p>


2 Comments