• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to identify h:message within a datatable?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The h:outputText id attribute should match the h:message for attribute in order to display the error message. And you should not need an id attribute for h:message
 
Chris Gabel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion, K. Tsang, but it didn't work.

I changed the XHTML to be:


... and the bean code to be:


Am I missing something?
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Chris Gabel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Chris Gabel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic