users@glassfish.java.net

JSF validation question

From: <glassfish_at_javadesktop.org>
Date: Sun, 19 Aug 2007 21:38:22 PDT

I have a LineItem object that is part of an Order. The LineItem references a Product and contains a quantity. Because some ProductS are sold only in packs and not as individual items, I need to prevent the user from specifying an illegal quantity. For example, if the pack size = 4, the quantity can be a multiple of 4, but not 1, 2, 3, 5, etc.

I'm using an <h:dataTable> with <h:inputText> for the quantity for each LineItem.

I created a validator method to check the quantity the user, but I cannot figure out a way to obtain the LineItem object in the validator method. I need this so I can check the associated Product to see if the quantity entered by the user is valid.

I could check the quantity in the action method when the user presses the "Update Cart" button after changing a quantity, but I'd like to avoid that because by then, the quantity has been updated and I can't get the previous quantity to display to the user. [Note: I don't write the Order to the database until it is complete, so I can't get the Order back from the db.]

I tried to pass the Product's id in the UIComponent's id, by doing the following:

<h:inputText id="_#{lineItem.product.id}"

but it didn't work -- when i called UIInput.getId(), it only returned "_".

Any ideas on how to handle this?

Thanks very much,

Rick
[Message sent by forum member 'rickhoro' (rickhoro)]

http://forums.java.net/jive/thread.jspa?messageID=231547