Is it possible to get specific element in list or array using EL in a Java EE page (Facelets or JSP), or do I have to create a custom EL method?
You can use the brace notation [] wherein you specify the (zero-based) index of the element you'd like to retrieve.
<p>This is the 3rd item of the list: #{bean.list[2]}</p>
This syntax does basically the same as bean.getList().get(2).
This is equivalent for arrays.
<p>This is the 3rd item of the array: #{bean.array[2]}</p>
This syntax does basically the same as bean.getArray()[2].
See also:
Our EL wiki page
Related
Having 2 lists, I want check which values of List1 are in List2. I'm trying as below but I get error
List1 = {3,2,8,7,5}
List2 = {1,3,4,2,6,7,9}
= List.Transform(List1, each Text.Contains(List2, _))
Expression.Error: We cannot convert a value of type List to type Text.
Details:
Value=[List]
Type=[Type]
My expected output would be 3,2,7.
How can I do this?
See List.Intersect Documentation
Intersect = List.Intersect({List1,List2})
#horseyride has probably the best answer but using your original logic, you could also write the intersection like this:
List.Select(List1, each List.Contains(List2, _))
This uses Select instead of Transform since you are trying to select/filter instead of changing the elements and uses the appropriate List type instead of Text for the Contains part.
I'm trying to create a list in Markdown. As I've read in some documentation, if I write this Markdown code:
My list
* first item
* second item
* third item
Not in the list
I would get as result the same as if I write this in HTML:
<p>My list</p>
<li>
<ul>first item</ul>
<ul>second item</ul>
<ul>third item</ul>
</li>
<p>Not in the list</p>
I use Atom as editor and its Markdown previewer and everything is OK, but when I use pandoc to convert my Markdown file as follows:
pandoc test.md -o test.odt
what I get is this:
My list * first item * second item * third item
Not in the list
Where am I doing wrong?
There are two possible solutions to your problem:
Add a blank line between the paragraph and the list (as #melpomene mentioned in a comment).
My list
* first item
* second item
* third item
Not in the list
Leave out the blank line and tell Pandoc to use commonmark as the input format rather than the default, markdown.
pandoc -f commonmark -o test.odt test.md
The "problem" is that the Atom editor uses a CommonMark parser and, by default, Pandoc uses an old-school Markdown parser which mostly follows these rules and the reference implementation (markdown.pl). In fact, the Commonmark spec specifically acknowledges this difference:
In CommonMark, a list can interrupt a paragraph. That is, no blank
line is needed to separate a paragraph from a following list:
Foo
- bar
- baz
<p>Foo</p>
<ul>
<li>bar</li>
<li>baz</li>
</ul>
Markdown.pl does not allow this, through fear of triggering a list
via a numeral in a hard-wrapped line:
The number of windows in my house is
14. The number of doors is 6.
If you want common behavior among your tools, then you need to only use tools which follow the same behavior.
In haml the following would produce the correctly nested HTML:
%p Hi There I'm inside this paragraph
%button I'm also inside this paragraph
Produces:
<p> Hi There I'm inside this paragraph <button>I'm also inside this paragrpah</button></p>
In Emblem.js if I do:
p Hi There I'm inside this paragraph
%button I'm also trying to be in the paragraph
It produces this:
<p> Hi There I'm inside this paragraph %button I'm also trying to be in the paragraph</p>
Does anyone know how to nest content and elements inside emblem.js?
p Hi There I'm inside this paragraph
button I'm also trying to be in the paragraph
without the % will do the trick
I can recommend checking out http://emblemjs.com/syntax/ , it's a great resource that briefly explains every possible use case.
I have the following repeated piece of the web-page:
<div class="txt ext">
<strong class="param">param_value1</strong>
<strong class="param">param_value2</strong>
</div>
I would like to extract separately values param_value1 and param_value2 using Xpath. How can I do it?
I have tried the following constructions:
'//strong[#class="param"]/text()[0]'
'//strong[#class="txt ext"]/strong[#class="param"][0]/text()'
'//strong[#class="param"]'
none of which returned me separately param_value1 and param_value2.
P.S. I am using Python 2.7 and the latest version of Scrapy.
Here is my testing code:
test_content = '<div class="txt ext"><strong class="param">param_value1</strong><strong class="param">param_value2</strong></div>'
sel = HtmlXPathSelector(text=test_content)
sel.select('//div/strong[#class="param"]/text()').extract()[0]
sel.select('//div/strong[#class="param"]/text()').extract()[1]
// means descendant or self. You are selecting any strong element in any context. [...] is a predicate which restricts your selection according to some boolean test. There is no strong element with a class attribute which equals txt ext, so you can exclude your second expression.
Your last expression will actually return a node-set of all the strong elements which have a param attribute. You can then extract individual nodes from the node set (use [1], [2]) and then get their text contents (use text()).
Your first expression selects the text contents of both nodes but it's also wrong. It's in the wrong place and you can't select node zero (it doesn't exist). If you want the text contents of the first node you should use:
//strong[#class="param"][1]/text()
and you can use
//strong[#class="param"][2]/text()
for the second text.
I want to retrieve the position of a nested list given an element of the nested list. Is this possible without traversing through all the nested lists?
For example, given a list of lists, [[1.1 a b][1.2 c d][1.3 e f]] I'd like to get the position 1 given element 1.2 .
This is similar to what was asked in this question: NetLogo : How to do multiple operations on lists (find, get , replace, remove , search elements within lists , ....)
In your particular case, you can use a combination of map to extract the sublist element you're looking for and position to get its index:
observer> show position 1.2 map first [[1.1 "a" "b"][1.2 "c" "d"][1.3 "e" "f"]]
observer: 1