Hi everyone, I need to load an entitycombobox depending on the values load in 2 others one. ¿how can I made it?
Hi Enrique,
Have you seen this example: Cascading dropdowns?
It shows the list of Moons depending on the list of Planets, using the following JPQL for Moons:
select m from Moon m where m.planet = :container_planetsDc order by m.name
To add dependency to another data container just add a condition to the query, something like this:
select m from Moon m
where m.planet = :container_planetsDc
and m.atmosphereCategory = :container_atmosphereCategoriesDc
order by m.name
Regards,
Konstantin
Thanks Konstantin, but I already did that.
And when I tried to get into the detail view I get this error.
Maybe the entityComboBox linked to ramoesDc contains an empty value?
I don’t think so, if I put in que query only the entityComboBox linked to ramoesDC I don’t have that problem. When I put the entityComboBox linked to aseguradorasDc first, I get the same error.
Most probably one of your dropdowns has an empty value at first. To handle the situation when some parameters are empty, place the query conditions inside the special markup as described in Query Conditions.
See the moonsDc query here:
<collection id="planetsDc" class="com.company.demo.entity.Planet">
<fetchPlan extends="_base"/>
<loader id="planetsDl" readOnly="true">
<query>
<![CDATA[select e from Planet e order by e.name]]>
</query>
</loader>
</collection>
<collection id="atmospheresDc" class="com.company.demo.entity.Atmosphere">
<fetchPlan extends="_base"/>
<loader id="atmospheresDl" readOnly="true">
<query>
<![CDATA[select e from Atmosphere e order by e.description]]>
</query>
</loader>
</collection>
<collection id="moonsDc" class="com.company.demo.entity.Moon">
<fetchPlan extends="_base"/>
<loader id="moonsDl" readOnly="true">
<query>
<![CDATA[select e from Moon e]]>
<condition>
<and>
<c:jpql>
<c:where>e.planet = :container_planetsDc</c:where>
</c:jpql>
<c:jpql>
<c:where>e.atmosphere = :container_atmospheresDc</c:where>
</c:jpql>
</and>
</condition>
</query>
</loader>
</collection>
Attached the whole project:
demo.zip (112.6 KB)
Thank you for your help Konstantin, it’s already works