I am studying Spring WebFlow, and I am apparently missing a key concept of Spring in a sample application I am studying. I have the following XML which gets the property allItems from a shopping cart.
<on-start>
<evaluate expression="order.setBooksOrdered(shoppingCart.allItems)" />
</on-start>
However, I do not see a method or property by that name in the ShoppingCart class below. Although of course there is a getAllITems() class. It all compiles and works, but I am apparently missing a key concept here.
@Component
@Scope("session")
public class ShoppingCart implements Serializable {
private List<Book> shopping = new ArrayList<Book>();
public void addItem(Book newItem) {
this.shopping.add(newItem);
}
public List<Book> getAllItems() {
return shopping;
}
public void clear() {
this.shopping.clear();
}
}
Can someone point me in the direction of the key concept I am missing?
Take a look at JavaBean documentation.
If you have a JavaBean which has a JavaBean property, you access that property (in this case
allItems) with a methodget<propertyName>(in this casegetAllItems()) oris<propertyName>when the property is a boolean. The actual name of the field is irrelevant to the JavaBean standard.There is more to the JavaBean specification than just that. I recommend taking a look at the linked documentation.
So to access the
allItemsproperty of theshoppingCartbean, you will actually be triggering thegetAllItems()method.