In a complex JSP/Servlet application, would you use both JavaBeans and custom actions or one or the other? It seems like their functionality overlaps quite a bit. |
Answer: Yes, it does and there’s no clear cut answer for when one component type is the “right” choice. Often you end up using both types.I touch on this in the book in a couple of places. In Chapter 8, I say:
An example of what I mean here is a bean with customer information properties and custom actions that process that information. You can use a <jsp:useBean> action to capture the input from a form, and custom actions to validate the captured data and to store it in a database: <jsp:useBean id="custInfo" class="com.mycompany.CustomerInfoBean"> <jsp:setProperty name="custInfo" property="*" /> </jsp:useBean> <mytags:validateCustomerInfo name="custInfo" forwardOnInvalid="input.jsp" /> <mytags:storeCustomerInfo name="custInfo" nextPage="confirm.jsp" /> In Chapter 16 I say:
Hence, a bean that does something (such as the validation and storing above) can be wrapped in a custom action for use in a JSP page, and at the same time be used as is in a servlet or some other Java class. The counter bean and custom actions in Chapter 8 are examples of that. Instead of a bean, a custom action can of course wrap a regular utility class, such as the cookie and string utility classes used in the custom action examples in Chapter 16. |