JSP: Beans from factories?

Discussion in 'Java' started by Kai Grossjohann, Dec 17, 2003.

  1. I have an object which has a factory method which returns objects that
    I would like to use as beans in JSPs.

    <jsp:useBean id="foo" class="blarfl"/> will call the constructor of
    the blarfl class, though, so that's not what I want.

    I can use a scriptlet along the lines of

    <% Factory fact = new Factory();
    Blarfl b = fact.findBlarfl(); %>

    But then I don't know how to make b into a bean such that I can use
    <jsp:setProperty/> and friends on it.

    Maybe it works to use <c:set/>? How to do that?

    Kai
     
    Kai Grossjohann, Dec 17, 2003
    #1
    1. Advertising

  2. Kai Grossjohann <> wrote in message news:<>...
    > I have an object which has a factory method which returns objects that
    > I would like to use as beans in JSPs.
    >
    > <jsp:useBean id="foo" class="blarfl"/> will call the constructor of
    > the blarfl class, though, so that's not what I want.
    >
    > I can use a scriptlet along the lines of
    >
    > <% Factory fact = new Factory();
    > Blarfl b = fact.findBlarfl(); %>
    >
    > But then I don't know how to make b into a bean such that I can use
    > <jsp:setProperty/> and friends on it.


    See item #7 of http://java.oreilly.com/news/jsptips_1100.html
     
    Chris Riesbeck, Dec 17, 2003
    #2
    1. Advertising

  3. (Chris Riesbeck) writes:

    > See item #7 of http://java.oreilly.com/news/jsptips_1100.html


    It seems that they are telling me to do this:

    <jsp:useBean id="foo" class="Foo" scope="request"/>
    <%
    foo = factory.makeFoo(parm1, parm2);
    pageContext.setAttribute("foo", foo, PageContext.REQUEST_SCOPE);
    %>
    <jsp:setProperty name="foo" property="bar" value="42"/>

    What if I can't say <jsp:useBean /> in the first line? My class Foo
    does not have a no-arg constructor.

    I'm not 100% sure but I seem to recall that just putting stuff into
    the request scope was not sufficient for a subsequent <jsp:setProperty
    ..../> to succeed.

    Kai
     
    Kai Grossjohann, Dec 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maxi

    Beans and JSP

    Maxi, Jul 12, 2003, in forum: Java
    Replies:
    1
    Views:
    790
    Andy Flowers
    Jul 12, 2003
  2. GoostleeK
    Replies:
    7
    Views:
    503
    GoostleeK
    Dec 29, 2003
  3. Dan Valero

    Confused about jsp beans and scope

    Dan Valero, Jan 7, 2004, in forum: Java
    Replies:
    1
    Views:
    434
    Gerbrand van Dieijen
    Jan 7, 2004
  4. Torsten Schmeissel
    Replies:
    0
    Views:
    440
    Torsten Schmeissel
    Apr 29, 2005
  5. Replies:
    1
    Views:
    468
    Oliver Wong
    Oct 2, 2006
Loading...

Share This Page