Pergunta

I couldn't find it anywhere only about the equivalent in java but does anyone know what the EL equivalent is of getComponent("name").value?

Foi útil?

Solução

It's whatever the component is bound to... so if your page includes:

<xp:inputText value="#{currentDocument.subject}" />

...then this will display the same result:

<xp:text value="#{currentDocument.subject}" />

You can also reference the value using any of the standard EL operators; e.g.:

<xp:label rendered="#{not(empty(currentDocument.subject))}" ...>
<xp:comboBox rendered="#{currentDocument.totalAmount gt 1000}" ...>
<xp:panel rendered="#{currentDocument.optIn eq 'Yes'}" ...>

And EL also support "associative array" syntax, which is handy when needing to refer either to dynamically named properties, or properties that are editable outside a Custom Control but you need to reference them inside a Custom Control. For instance, if you define dataSource and propertyName as custom properties for your Custom Control, you could pass them in from a context that "knows" what they are:

<xc:dynamicLabel dataSource="currentDocument" propertyName="subject" />

...then reference them inside that Custom Control:

<xp:label text="#{compositeData.dataSource[compositeData.propertyName]}" />

And, of course, all of this works with any of the types that the XPages engine knows how to reference via EL:

  • SSJS objects
  • Java Maps (i.e. scope variables)
  • Instances of DataObject (standard Domino document data sources, custom implementations, etc.)
  • Any valid Java bean (adheres to bean conventions)

To be precise, when EL is interpreted, the variable resolver checks to see if it's one of the first three, and if it is, evaluates any properties in a manner specific to that type. If it isn't one of those first three, it assumes it's a bean.

To sum up, any given component doesn't "know" its own value. If you programmatically get a handle on a component and call its getValue method, that method checks to see if its value is a value binding (EL, SSJS, etc.). If it is, then it evaluates that expression and returns the result. So if you need that same result elsewhere, just use the same expression in the alternate location as well, because it will return the same result...... just don't bind the value attribute of multiple editable components to the same expression; that can produce unpredictable results.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top