I have an object called Perfil that has an OneToMany relationship with another object called Nivel.
So, in the Perfil Entity I have a Nivel list.
When I have to include a Perfil, I have to include a new Nivel because some attributes that I've to include, view or edit are in the Nivel table.
So, my question is: How to include a new Perfil using the Nivel list?
I tried something like this, but didn't work out.
<s:decorate id="nmPerfilField" template="layout/edit.xhtml"> <ui:define name="label">Nome Perfil</ui:define> <h:inputText id="nmPerfil" required="true" size="50" maxlength="50" value="#{pmnPerfilHome.instance.nmPerfil}"> <a:support event="onblur" reRender="nmPerfilField" bypassUpdates="true" ajaxSingle="true"/> </h:inputText> </s:decorate> <s:decorate id="nmNivelField" template="layout/edit.xhtml" rendered="#{pmnPerfilHome.managed}"> <ui:define name="label">Nome Nível</ui:define> <h:inputText id="nmNivel" required="true" size="50" maxlength="50" value="#{pmnPerfilHome.instance.pmnNivels.add(0,nmNivel)}"> <a:support event="onblur" reRender="nmNivelField" bypassUpdates="true" ajaxSingle="true"/> </h:inputText> </s:decorate>
Here goes my Perfil Entity:
...... private List<PmnNivel> pmnNivels = new ArrayList<PmnNivel>(0); ...... @OneToMany(fetch = FetchType.LAZY, mappedBy = "pmnPerfil") public List<PmnNivel> getPmnNivels() { return this.pmnNivels; } public void setPmnNivels(List<PmnNivel> pmnNivels) { this.pmnNivels = pmnNivels; }
There's a method in the Perfil Home Object:
public List<PmnNivel> getPmnNivels() { return getInstance() == null ? null : new ArrayList<PmnNivel>( getInstance().getPmnNivels()); }
Thanks for your help!