<script>
for(i=0; i < ${mybean.myStrings.length} ; i++ ) { document.write(${mybean.myStrings[i]}) } </script> ${mybean.myStrings.length} will work (if I recall correctly). The problem is that the EL expression inside the loop must be evaluated on the server side when the JSP/JSF page is created, but the JavaScript is processed by the browser. If you really needed to do something like the above, you have to drive the loop with Java inside your JSF page. First, of course, you should realize your JSF backing session beans will be available in the usual way through the built-in JSP session object. <% MyBean mybean=(MyBean)session.getAttribute("mybean");
for(int i=0;i < mybean
%>
<script>
document.write(<% myBean.myString[i] %>);
</script>
<%
}
%>
This example is really artificial, of course, but there really are cases when I needed to do things like this. OK, probably there is a better way.
No comments:
Post a Comment