djmj
djmj

Reputation: 5544

jsf send selectOneMenu value as direct request managed bean

I have a selectOneMenu that manages a relation between two Objects A and B. Where A is fixed and B is selectable via the menu.
On form submit B is send to the bean for further processing (creating and saving relationship object AToB).

Not working case!

<h:selectOneMenu value=#{b}>
    <!-- b items from bean -->
</h:selectOneMenu>
<h:commandButton action="#{bean.addBToSelA(b)}"/>

<managed-bean>
    <description>B Entity Request Bean</description>
    <managed-bean-name>b</managed-bean-name>
    <managed-bean-class>B</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

Working case!

But if the selectOneMenu value is a nested property of a different managed bean it works. (as example AToB)

<h:selectOneMenu value=#{aToB.b}>
    <!-- b items from bean -->
</h:selectOneMenu>
<h:commandButton action="#{bean.addBToSelA(aToB.b)}"/>

<managed-bean>
    <description>AToB Entity Request Bean</description>
    <managed-bean-name>aToB</managed-bean-name>
    <managed-bean-class>AToB</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

Note: It is enough if my "b" is just a property of a different request managed bean.

Can someone be so kind and explain why?

Upvotes: 0

Views: 859

Answers (1)

BalusC
BalusC

Reputation: 1108642

Because JSF has already created the bean instance beforehand. It won't be overridden with the model value if the instance already exist in the scope. Remove the <managed-bean> from faces-config.xml and it'll work just fine.


Unrelated to the concrete problem, you seem to be already using JSF 2.x. Why sticking to the old JSF 1.x style faces-config.xml configuration? Just use @ManagedBean annotation (on real backing bean classes only, of course).

Upvotes: 1

Related Questions