0

i have a weird problem and i can't know the main cause, i have these login page, which uses <f:ajax event=""> to validate username and password:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head></h:head>
<h:body>
<h:form>
<h:panelGrid columns="3">
Name:
<h:inputText id="name" value="#{validateBean.name}"
    validator="#{validateBean.validateName}">
    <f:ajax event="blur" render="nameError" />
</h:inputText>
            <h:message for="name" id="nameError" style="color:red" />

Password:
<h:inputText id="password" value="#{validateBean.password}"
    validator="#{validateBean.validatePassword}">
    <f:ajax event="blur" render="passwordError" />
</h:inputText>
        <h:message for="password" id="passwordError" style="color:red" />
                <h:commandButton value="Login" action="# {validateBean.login}" />

</h:panelGrid>

these JSF works properly, but the problem appears when i place the same above components under a <ui:composition template=""> inorder to use these page with a template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/WEB-INF/Templates/BasicTemplate.xhtml">
<ui:define name="content">
    <center>
        <h:form>
            <h:panelGrid columns="3">
Name:
<h:inputText id="name" value="#{validateBean.name}"
                    validator="#{validateBean.validateName}">
                    <f:ajax event="blur" render="nameError" />
                </h:inputText>
                <h:message for="name" id="nameError"  style="color:red" />
Password:
<h:inputText id="password" value="#{validateBean.password}"
                    validator="# {validateBean.validatePassword}">
                    <f:ajax event="blur" render="passwordError"  />
                </h:inputText>
                <h:message for="password" id="passwordError"   style="color:red" />
                <h:commandButton value="Login" action="# {validateBean.login}" />
            </h:panelGrid>
        </h:form>
    </center>
</ui:define>
</ui:composition>
</html>

for more clarity, here's the jsf template page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title><ui:insert name="title">Default title</ui:insert></title>
</head>

<body>

<div id="header">
<ui:insert name="header">

    <ui:include src="header.xhtml"/> // normal page contains plain text
 </ui:insert>
 </div>

 <div id="content">
 <ui:insert name="content">
    Content area.  See comments below this line in the source.

  </ui:insert>
  </div>

   <div id="footer">
   <ui:insert name="footer">

    <ui:include src="footer.xhtml"/> // normal page contains plain text
    </ui:insert> 
    </div>

    </body>

     </html>

when i tried the later approach the AJAX action doesn't fire at all, please any one explain to me why that happens??

Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
  • 1
    This question is not answerable without seeing the template's source code which you have completely omitted from the question for some unclear reason. In the meanwhile, work through http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 yourself to exclude all possible causes. In the future questions, please post sufficiently information so that one (including yourself!) would be able to reproduce exactly the described problem in a completely blank project with everything set to default. – BalusC Apr 01 '13 at 03:40

1 Answers1

0

You used <head> instead of <h:head> in your master template. This way JSF is unable to auto-include the required jsf.js JavaScript file for the ajax works.

Fix it accordingly:

<html ...>
    <h:head>
        ...
    </h:head>
    <h:body>
        ...
    </h:body>
</html>

See also:

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