-1

So I have a managed viewscope bean, and I have a html page with a container

<div id="container>...</div>

I want to go through a list of Strings in the managedBean and append a whole bunch of selectOneMenu items into the container from the Java side based on what's in that list.

Can I do that? And if so, what is the easiest way. Also I am using Primefaces and am open to use Javascript but would prefer to avoid it.

hthomos
  • 297
  • 2
  • 8
  • 16
  • 1
    The requirement sounds somewhat strange and cannot be encouraged without knowing the concrete functional requirements. "*based on what's in that list.*" This can simply be done by binding the list in question (by list, I mean a collection type like `java.util.List`) to a `

    `. There should not be a need to consider hazardous/tedious Java code ways which are not easily readable/maintainable.

    – Tiny Jan 13 '15 at 19:20

2 Answers2

0

There are, in fact, two ways I know to do that. The first (and probably the easiest) one is to inject html directly via the following method:

org.primefaces.context.RequestContext.getCurrentInstance().execute("<input type='text' />");

In this case, you will just attatch static html or javascript to your page.

In the case you want to add jsf components, you can manipulate components from the backing bean by using binding. Then you can instantiate components as simple java objects. (What is component binding in JSF? When it is preferred to be used?)

Community
  • 1
  • 1
David Krenkel
  • 393
  • 2
  • 25
0

I was being stupid.... I could easily just add a ... to the xhtml and it would have looped through a list I get from the bean side.

hthomos
  • 297
  • 2
  • 8
  • 16