This discussion is archived
7 Replies Latest reply: Nov 12, 2012 3:07 AM by markoj RSS

View attribute label as EL expression

markoj Newbie
Currently Being Moderated
Hello!
Is it possible to insert EL expression into view attribute's label property programmatically?

For example:
+<af:inputText value="#{row.bindings.AttributeName.inputValue}"+
*label="#{bindings.SomeViewObject.hints.AttributeName.label}"*+
+required="#{bindings.SomeViewObject.hints.AttributeName.mandatory}"+
+columns="#{bindings.SomeViewObject.hints.AttributeName.displayWidth}"+
+maximumLength="#{bindings.SomeViewObject.hints.AttributeName.precision}"+
+shortDesc="#{bindings.SomeViewObject.hints.AttributeName.tooltip}"+
+id="it2">+

would then be

+<af:inputText value="#{row.bindings.AttributeName.inputValue}"+
+*label="#{translation['SomeViewObject.AttributeName']}"*+
+required="#{bindings.SomeViewObject.hints.AttributeName.mandatory}"+
+columns="#{bindings.SomeViewObject.hints.AttributeName.displayWidth}"+
+maximumLength="#{bindings.SomeViewObject.hints.AttributeName.precision}"+
+shortDesc="#{bindings.SomeViewObject.hints.AttributeName.tooltip}"+
+id="it2">+

I would like to replace all attribute's label properties of view iterators with EL expressions which would get the right translations (with a generic solution hopefully).
My current solution executes EL expressions that get the right translation in overriden method *getAttributeDefImpls* in *ViewDefImpl* class and then I set view labels with

+attributeDefImpls&#91;i&#93;.setProperty(AttributeHints.ATTRIBUTE_LABEL, TranslatedLabel);+

But every time I select different language in select one choice, labels aren't refreshed, because +getAttributeDefImpls+ is not executed again on page refresh. But if I could insert an expression into label value, all labels would get refreshed translations on language change (and page refresh).
Please, I would appreciate any useful information.
Regars, Marko

PS: Oh, I use JDeveloper 11.1.2.1.0
  • 1. Re: View attribute label as EL expression
    user404 Pro
    Currently Being Moderated
    You should take a look at this :
    http://docs.oracle.com/cd/E15051_01/web.1111/b31973/af_global.htm
  • 2. Re: View attribute label as EL expression
    markoj Newbie
    Currently Being Moderated
    I don't think that solves my problem.
    I already read this article few times in the past. My translations are extracted from database table and for a majority of time it's working great. I have a problem only with view attribute label's translations. They do work, but I have a problem with refreshing of translations whenever I change the language (and reload the page)
    The problem is I override protected AttributeDefImpl[] getAttributeDefImpls() in my CustomViewDefImpl class (which extends ViewDefImpl), which my view objects then extend. In that method I set label values (that is I set label text for every view attribute) with

    +attributeDefImpls.setProperty(AttributeHints.ATTRIBUTE_LABEL, TranslatedLabel);+
    +//TranslatedLabel is extracted from database+

    Whenever I reload the page, getAttributeDefImpls is not invoked - it gets called only the first time, when I load the page. If I change the language and reload the page, all other translations are changed according to my new language, ONLY VIEW LABELS are still in their previous language. I would solve this if I could somehow programmatically insert EL expression as label value

    For example:
    +attributeDefImpls&#91;i&#93;.setProperty(AttributeHints.ATTRIBUTE_LABEL, "#{translate['SomeViewName.SomeAttributeName']}");+

    But of course the solution is not that easy :(

    OK, I hope that clears up my issue :)
    Any other suggestions?
    Regards, Marko

    Edited by: markoj on Nov 8, 2012 8:27 AM
  • 3. Re: View attribute label as EL expression
    kdario Expert
    Currently Being Moderated
    When you change language, you can try to invoke some method exposed in your AM which will iterate through all attribute definitions and call setProperty() with new value.

    Dario
  • 4. Re: View attribute label as EL expression
    markoj Newbie
    Currently Being Moderated
    OK, I could try that.
    But only problem is that my solution for translations is included into main application (Framework) like ADF library (TranslationModule jar file) that in general does not have access to application's every application module and view objects. But it's a start ;)
  • 5. Re: View attribute label as EL expression
    markoj Newbie
    Currently Being Moderated
    Can anyone else suggest more general solution?
  • 6. Re: View attribute label as EL expression
    kdario Expert
    Currently Being Moderated
    >
    would then be

    <af:inputText value="#{row.bindings.AttributeName.inputValue}"
    label="#{translation['SomeViewObject.AttributeName']}"
    >
    Current EL version in ADF doesn't support functions with parameters, but supports java.util.Map.
    So, you can implement your own map and use that as translation utility, for example:
    public class TranslationMap implements Map{
      public Object get(Object key){
          return getTranslation(key);
      }
      
      // create dummy implementations for other methods in Map interface
    }
    Then instantiate this map in your bean and use something like this:
    label="#{yourBean.translation['someKey']}"
    But, this will not help you with dynamic components(like af:query)

    Instead of this, you can override getAttributeHints(int i) in ViewRowImpl class, something like this
    public AttributeHints getAttributeHints(int i){
       String attributeName = getAttributeNames();

    if(languageChanged(attributeName)){
    String newLabel = getNewLabel(attributeName);
    AttributeDefImpl adi = (AttributeDefImpl)findAttributeDef(name);

    adi.setProperty(AttributeHints.ATTRIBUTE_LABEL, newLabel);
    adi.setProperty(AttributeDefImpl.ATTRIBUTE_LABEL, newLabel);
    // etc.
    }

    return super.getAttributeHints(i);
    }
    Dario
    
    Edited by: kdario on Nov 9, 2012 2:43 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • 7. Re: View attribute label as EL expression
    markoj Newbie
    Currently Being Moderated
    OK that first part of your post I got covered
    with
    +<f:loadBundle basename="translations.model.CustomResources" var="translation"/>+
    I can get any translation on a page through EL expression
    +#{translation['TranslationKeyName']}+

    I have a problem with refreshing label's after page refresh when I select different language in select one choice component.

    For now I managed to do the following (with your help of course ;)):
    When I select different language, I get all active view iterator bindings on current page programmatically in a bean (that is all view objects that are used on the current page). Through getting all active view iterators I can re-call setting all iterator view label's translations.

    <pre class="jive-pre">
    // How I get view iterator
    DCIteratorBinding regionIterator = (DCIteratorBinding)iteratorBinding;
    ViewObjectImpl viewObjectImpl = (ViewObjectImpl)regionIterator.getViewObject();
    ViewDefImpl viewDefImpl = (ViewDefImpl)viewObjectImpl.getDef();
    viewDefImpl.getAttributeDefs(); // Re-set view label's translations in view definition
    viewObjectImpl.getAttributeDefs(); // Re-set view label's translations in view object

    // How I refresh a page
    fc = FacesContext.getCurrentInstance();
    refreshpage = fc.getViewRoot().getViewId();
    ViewH = fc.getApplication().getViewHandler();
    UIV = ViewH.createView(fc,refreshpage);
    UIV.setViewId(refreshpage);
    fc.setViewRoot(UIV);
    </pre>


    When I debug I can see that view definition's getAttributeDefImpls (in CustomViewDefImpl) is called again where I try to re-set label's translations - because of the viewDefImpl.getAttributeDefs();
    But when I evaluate EL to get the translation it returns null (Only when selecting different language).
    <pre class="jive-pre">
    TranslatedLabel = evaluateEL("#{translation['" + translationKey + "']}")
    </pre>
    I even tried to re-set translations in my CustomViewObjectImpl in overriden method getAttributeDef with
    viewObjectImpl.getAttributeDefs();
    where
    <pre class="jive-pre">
    TranslatedLabel = evaluateEL("#{translation['" + translationKey + "']}")
    </pre>
    does return the right (NON NULL selected language) translation and I set attribute labels with new translation, but after the page renders, labels still have their old translation even though
    <pre class="jive-pre">
    attrDefImpl.setProperty(AttributeHints.ATTRIBUTE_LABEL, TranslatedLabel);
    </pre>
    sets the new lanugage translation in CustomViewObjectImpl.

    It's like the page is rendered, and then label's translations are set. If I refresh a page again, the right translation hints are displayed. Anyone knows why on page refresh
    <pre class="jive-pre">
    TranslatedLabel = evaluateEL("#{translation['" + translationKey + "']}")
    </pre>
    returns null in CustomViewDefImpl and NON null in CustomViewObjectImpl?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points