1

I intend to verify a field usernameTxt in form with bootstrap below, with a reference to BalusC answer and Aleksei Loginov answer

<div class="form-group">
                <label class="control-label col-sm-2" for="usernameTxt">Fullname(*):</label>
                <div class="col-sm-10">
                    <h:inputText type="text" class="form-control" id="usernameTxt"
                        a:placeholder="Enter your name" required="true"
                        requiredMessage="Fullname is required"
                        value="#{data.personalInformation.username}"></h:inputText>
                    <h:panelGroup layout="block" rendered="#{not empty facesContext.getMessageList('usernameTxt')}" class="alert alert-danger">
                        <h:message for="usernameTxt"></h:message>
                    </h:panelGroup>
                </div>
            </div>

The wish is that if the input text is empty then it will render the block <h:panelGroup>, and the result should be like enter image description here

(That photo is when I remove the not condition in the rendered property). I can't make the block rendered conditionally correctly. Is there any syntax in the render condition, or am I missing something here ?

ThangLeQuoc
  • 2,272
  • 2
  • 19
  • 30
  • Please also read this: https://stackoverflow.com/questions/14790014/ajax-update-render-does-not-work-on-a-component-which-has-rendered-attribute – Kukeltje Aug 17 '17 at 06:50

1 Answers1

1

The problem is solved.

It takes me a whole day to find out that the actual usernameTxt id on page has been rendered and it's not like what I expected

enter image description here

So I have to change the condition back to

<h:panelGroup layout="block"
                        rendered="#{not empty facesContext.getMessageList('form:j_id_9:useridTxt')}"
                        class="alert alert-danger">
                        <h:message for="useridTxt"></h:message>
                    </h:panelGroup>

and it solved my problem

ThangLeQuoc
  • 2,272
  • 2
  • 19
  • 30