0

I am trying to include an EJS file in my XHTML file so that I could pass on the data to the managed bean. I tried by including withing in script tag as but i am not getting the value from the EJS file to XHTML file. Could anyone please help me in the proper way to include an EJS file in HTML/ XHTML file.

Thanks,

ind.ejs

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
</head>
<body>
    <h1> Date is: </h1>       <%= new Date() %>
      Room Type is:           <%= checkindt %> <br /> 
     Room Type is:            <%= roomtype %> 
</body>
</html>

app.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
<head>
 <script type="text/javascript" src="/ind.ejs" > </script>
 <title>My App</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
   <script type="text/javascript" >
      function setValue(){
          alert('app.xhtml');
          alert('cindt is: '+ checkindt);
         document.getElementById('myForm.cindt').value = checkindt;
      }
  </script>
</head>
   <body>
       <div>My app</div>
       <form name="myForm" >
           Date:   <input type="text" name="cindt" />            
           <button id="submit" onclick="setValue();" />
       </form>
   </body>
</html>

1 Answer 1

2

There may be a better solution than using ejs, but I will attempt to answer this question anyways.

1) Download a browser compatible version of EJS. Try clicking Here to download or go here.

2) Inlude it in you page:

<script src="ejs.js"></script>
<script>
 // your code here
</script>

3) Render/Compile it:

From text:

<script src="ejs.js"></script>
<script>
  var ejsResult = new EJS({
          text: "<div>Room number is: <%= roomnumber %> <br /> Room Type is: <%= roomtype %> </div>"
      }).render({roomnumber: "111", roomtype: "Suite"})

  someElement.innerHTML = ejsResult;
</script>

From a url:

<script src="ejs.js"></script>
<script>
  var ejsResult = new EJS({
          url: "templateLocation.ejs"
      }).render({roomnumber: "111", roomtype: "Suite"});

  someElement.innerHTML = ejsResult;
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.