This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to place an error message beside a field in a datatable that it applies to, but I'm having trouble identifying it in the backing bean. I have an area on the top of my form for non-field-specific errors/info, but when the error is specific to a field (i.e. "email") I want the message to appear there.
This is my XHTML: (I've removed other non-relevant sections of the form for clarity)
This is my backing bean:
When I run the code, I get the error message:
[05/06/13 13:50:28:371 PDT] 00000026 RenderRespons W There are some unhandled
FacesMessages, this means not every FacesMessage had a chance to be rendered.
These unhandled FacesMessages are:
- Email address cannot be left blank when selecting email delivery.
Does anyone know what I'm doing wrong? I have a feeling the clientId of the message is not being set properly.
Did you have a <h:messages> tag in your XHTML file? Because the FaceContext.getCurrentInstance().addMessage() I think adds to this <h:messages> area.
Ideally you should use a Validator to validate your inputs. Also the Validator will definitely put the error message next to the invalid input. Yet it can get tricky with data tables, especially editable ones.
Further inspection, why is you email a outputText? There's nothing to validate.
If your email is indeed an inputText then your table would need an id attribute. I believe the id can't be found so the FaceContext doesn't know what to do.
The new id will then look like "DeliveryOptionsForm:<table id>:<row number>:emailLabel". Yes the row number is another thing you missed because it's in a table. Such attributes can be confirmed using tools like Firefox firebug.
Joined: Jan 17, 2011
I have a <h:messages> tag earlier on the page with the globalOnly="true" parameter. I have other messages which need to be displayed here. The ones specific to the Email field need to display next to the field they represent.
My page has a <h:outputText> tag to render the label for the field (Email) and the <h:inputText> field for the email is right below it. I want the error message to appear next to the Email label. I use a <f:validateRegex> tag to make sure it's a valid email, but that check passes with a blank email field. I can't use a "required=true" parameter because there are many Email fields on the screen, and I only want it to validate if the "Email" option is selected.
I'm using a dataTable to display 19 different sets of product types and their associated delivery options. The user can choose "MAILBOX", "EMAIL", or "NONE". When they choose email, an email label and input field appear (controlled by CSS).
How does the backing bean know which row number the error is occurring in? Is that passed as a parameter to the backing bean?
Joined: Jan 17, 2011
ACK! I feel stupid. I solved my own problem by putting the logic of the "required" parameter on the value of the drop down menu. That way it's all client side validation, and the backing bean is never called.
Thanks for the nudge in the right direction, K. Tsang.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How to identify h:message within a datatable?