However, this does not work with
For example, you have a select many check box where you want the user to select at least one or more bank account. So, you have an entity called Bank Account. Technically, you should be able to do it easily via the following code:
In the Stateful Bean,
@In(required=false, create=true)
@Out(required=false)
private List
In JSF code,
<h:selectManyCheckbox value="#{selectedAccount}"
layout="pageDirection">
<s:selectItems value="#{bankAccountList}" var="b"
label="#{b.accountName}" />
<s:convertEntity />
</h:selectManyCheckbox>
If you do so, you will get the conversion error, JSF complaining that you can't convert an array of string to an array of your object, in this case is List
In the Stateful Bean,
@In(required=false, create=true)
@Out(required=false)
private List
public List
return selectedAccount;
}
public void setSelectedPartners(List
selectedAccount = selected;
}
In JSF code,
<h:selectManyCheckbox value="#{nameOfYourBean.selectedAccount}"
layout="pageDirection">
<s:selectItems value="#{bankAccountList}" var="b"
label="#{b.accountName}" />
label="#{b.accountName}" />
<s:convertEntity />
</h:selectManyCheckbox>Using the getter and setter method make sure that, a new array list of BankAccount objects are created every time the form is submitted. So, it ensures that nothing unexpected happens. From my experience with Seam, annotations are good, but hiding the complexity to ease the programmers exposes us to another layer of debugging the framework and making sure it works as intended. In a lot of cases, getters and setters solve the problem that you have with @In and @Out.
Happy programming!.
No comments:
Post a Comment