-1

Or how would I convert a list of SelectItems to a JavaScript array?

Currently I am trying this:

<h:outputScript>
    <!-- Trailing commas valid as per http://www.ecma-international.org/ecma-262/5.1/#sec-11.1.5 -->
    var possibleOption = [<ui:repeat value="#{bean.mySelectItems}" var="selectItem">"#{selectItem.value}",</ui:repeat>];
    var firstOption = possibleOption[0];
</h:outputScript>

And it works, except that firstOption is undefined although possibleOption gets correctly populated when I check in the console. Maybe a timing problem? Is this even valid JSF, and if so, is there a "blocking" version of ui:repeat or something?

Or which other approach would you recommend?

user3280015
  • 279
  • 2
  • 10
  • possible duplicate of [Iterate on list in a backing bean with JavaScript](http://stackoverflow.com/questions/8644116/iterate-on-list-in-a-backing-bean-with-javascript) – Predrag Maric Mar 09 '15 at 10:39
  • You're taking the wrong perspective to look at the problem. Open the page in browser, rightclick and *View Source*. Locate the HTML/JS code generated by above piece of JSF code. Extract that into a standalone `.html` file. Focus the problem on that instead. Once nailed down the problem, then just alter the JSF code accordingly that it generates exactly the desired HTML/JS code. – BalusC Mar 09 '15 at 10:46

1 Answers1

0

Aaaah, I got it:

actually I was using:

var chosenOption = '#{empty bean.chosenOption ? possibleOption[0] : bean.chosenOption}';

Which is (now) of course wrong, because I was using possibleOption[0] inside the EL expression headbang

Sorry, one should always post the actual code I guess, not some dumbed down showcase ;)

user3280015
  • 279
  • 2
  • 10