If you want to build an online store application using Java, look no further. This article begins with an overview of the application, and then discusses the applicatin development process. It is taken from chapter 14 of JavaServer Faces Programming by Budi Kurniawan (McGraw-Hill, 2003; ISBN 0072229837).
<!-- the beginning of the Shopping Cart page --> <h:panel_list border="1"> <f:facet name="header"> <h:panel_group> <h:output_text value="Product Name"/> <h:output_text value="Quantity"/> <h:output_text value="Price"/> </h:panel_group> </f:facet> <h:panel_data var="item" valueRef="ShoppingCartBean.shoppingItems"> <h:output_text valueRef="item.productName"/> <h:output_number valueRef="item.quantity"/> <h:output_number valueRef="item.price"/> </h:panel_data> <f:facet name="footer"> <h:panel_group> <h:output_text value=" "/> <h:output_text value="Total"/> <h:output_number valueRef="ShoppingCartBean.total"/> </h:panel_group> </f:facet> </h:panel_list> <br> <h:command_button action="checkOut" commandName="checkOut" label="Check Out"> <f:action_listener type="buydirect.AppActionListener"/> <h:command_button> <!-- the end of the Shopping Cart page -->
</td> </tr> <tr> <td colspan="2"> <%-- The footer --%> <%@ include file="footer.jsp"%> </td> </tr> </table>
</h:form> </f:use_faces>
</body> </html>
The main part of the shoppingCart.jsp page (printed in bold) is a UIPanel component with a header facet and a footer facet. The dynamic part uses a panel_data tag, which gets its data from the shoppingItems property of the ShoppingCartBean. It has three columns that display the product name, quantity, and price, respectively:
</td> </tr> <tr> <td colspan="2"> <%-- The footer --%> <%@ include file="footer.jsp"%> </td> </tr> </table>
</h:form> </f:use_faces>
</body> </html>
Notice that for each UIInput component, a required_validator tag is used to make the component a mandatory field. At the end of the page is a UICommand button that the user can click to begin processing the order.
This chapter described how to build the BuyDirect online store application. The application uses various components in JSF, such as the UI components and validators, and has a number of managed beans.
The application is not a complete solution for an online store. However, it provides basic functionality that encompasses many features found in a commercial online store application. You could easily expand it to include capabilities for modifying the shopping cart and managing the store, for example.
This article is excerpted from JavaServer Faces Programming by Budi Kurniawan (McGraw-Hill, 2003; ISBN 0072229837). Check it out at your favorite bookstore today. Buy this book now.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.