12 July 2012

Java EE Applications: Calling a JSF page from a non-JSF page

Lab 6 replaces the CustomerController servlet with the ustomerDetails.xhtml JSF page.
Existing JSP pages need to be adapted to call the JSF page. Here's how you call a JSF page from a JSP or plain HTML page and pass a parameter to it.

  1. Change the AllCustomers.jsp page to call the JSF page.
    • Existing call to the servlet
    •  <a href="CustomerController?customerIdentity=<%= customers[i].getId()%>&submit=Get Customer">
    • New call to the JSF page
    • <a href="CustomerDetails.xhtml?customerIdentity=<%= customers[i].getId()%>">  
    • Change the JSF backing bean to receive parameters and call code when it is created by a GET request.
      1. Receive a GET parameter in an attribute
      2. @ManagedBean(name="customerDetails")
        @RequestScoped
        public class CustomerManagedBean {
        
           @ManagedProperty("#{param.customerIdentity}")
           private String customerId = "";
           ...
        }
      3. Call a method when the bean is created. The method looks up data using the value stored in the attribute in the previous step.
      4. @PostConstruct
        public void initCustomer() {
          if (customerId != null && customerId.length()!= 0){
            retrieveCustomer();
          }
        }
        

No comments:

Post a Comment