Instantiating JSF Managed Bean in Servlet and Passing Request (With Bean) to JSF -
this stupid question, simple answer. have been googling around past week attempting understand this, however, , have come empty.
i have simple servlet allows user access article posted user. servlet uses request url determine article get, , follows pattern:
http://www.example.com/servlet/article#
by using number in url, fetches article, puts corresponding article object, request-scoped managed bean, , attempts pass request jsf, article.xhtml, responsible rendering article page.
despite best efforts, appear unable pass article bean created in servlet jsf page. method pass article follows:
//import , package declaration public class articleservlet extends httpservlet { //various methods protected void processrequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { //retrieve article # article article = //create/fetch article using # request.setattribute("article", article); request.getrequestdispatcher("/dev/article.xhtml").forward(request, response); } }
the article class setup similar following:
@managedbean @requestscoped public class article { private string title; //other instance variables public article() { title = null; //init other variables default values } public article(integer articlenum) { //retrieve article , init using number, including title variable } //getter , setter methods public string gettitle() { return title; } public void settitle(string title) { this.title = title; } //more getters , setters }
finally, have jsf page itself, modified mockup web designer has made me. i've attempted 2 ways access bean within page:
<?xml version='1.0' encoding='utf-8' ?> <!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://xmlns.jcp.org/jsf/html"> <h:head> //header stuff, stylesheet links, etc. </h:head> <h:body> //template text, scripts, etc. <h2>#{article.title}</h2> </h:body>
the other method have attempted replacing outputtext tag #{article.title}
. first method, have posted, fills in space in h2 tag nothing, , second method literally prints characters #{article.title}
page.
am attempting use jsf isn't meant for? not passing bean through page properly? know should simple task, yet haven't been able figure out regardless of amount of searching i've done.
Comments
Post a Comment