1

when i click on the command button. validate method is getting called but the error message is not getting displayed..

here is my code..

<h:form id="form">
    <h:body>
        <p:panel style="width:500px">
            <h:outputLabel for="year" value="Select Year: *" style="font-weight:bold" />
            <p:selectOneMenu id="year" value="#{leaveBean.year}">
                <f:selectItem itemLabel="Select One" itemValue="null" />
                <f:selectItems value="#{leaveBean.yearDTO}" var="currentUser" itemValue="#{currentUser.name}" itemLabel="#{currentUser.name}" />
                <f:validator validatorId="LeaveCardValidator" />
            </p:selectOneMenu>
        </p:panel>

        <p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="updateList,updateDetails" id="button"/>
       <h:message for="year" style="color:red"/>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • are you sure your input was not valid? if input is valid so there will be no message. – erencan Sep 03 '13 at 06:42
  • am sure my input is invalid .. and also my action is also getting called even though validation fails... –  Sep 03 '13 at 08:17
  • Don't forget the form, as a seperate naming container so if you name your message id msg and try to update it it will be form:msg – Lyrion Sep 03 '13 at 09:19
  • I tried with .. it didnt worked.. –  Sep 03 '13 at 09:28

3 Answers3

4

You seem to expect that JSF auto-updates the <h:message> on every ajax request. This is untrue. Perhaps you're confusing with PrimeFaces <p:messages> or <p:growl> which have each an autoUpdate attribute which enables you to tell them to auto-update themselves on every ajax request.

You really need to make sure that the <h:message> is covered by the ajax update. Just give it an ID

<h:message id="yearMessage" ... />

and include it in the client ID collection of the ajax update

<p:commandButton ... update="updateList updateDetails yearMessage" />

An alternative would be to replace <h:message> by <p:messages autoUpdate="true">.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
3

Not sure where are the updateList and updateDetails are located but in the example give above you should use update="@form" instead or in addtion like this:

update="updateList updateDetails @form" 

so that the form will be rendered again...

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • 1
    No its not, you need to make sure you render/update the `h:message` with you commandButton. – Daniel Sep 03 '13 at 07:22
  • @erencan, try with plain `h:commandButton` with simple empty `f:ajax` , cause `p:commandButton` is boosted with default update of `@form` or something like this – Daniel Sep 03 '13 at 07:39
  • @erencan, I don't what have you tried and based on what you are saying this thigs, but read this: http://balusc.blogspot.co.il/2006/09/debug-jsf-lifecycle.html#ValidationError , even when validation fails the RENDER_RESPONSE will be called. – Daniel Sep 03 '13 at 07:57
  • 1
    Yes @Daniel you are right. update is necessary for `p:commandButton`. – erencan Sep 03 '13 at 08:25
  • rendering the form is not required for showing error messages as in the examples given by jsf.. –  Sep 03 '13 at 09:30
0

just use one of these : update the whole form in order to update the content of <h:message />

<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="@form" id="button"/>

or give the <h:message /> an id and id this id to the <p:commandButton/>
<h:message id="msg" for="year" style="color:red"/>

<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="updateList,updateDetails,msg" id="button"/>
primeFaceUser
  • 295
  • 2
  • 15