Struts, How to get at bean properties

Discussion in 'Java' started by Dave, Jul 13, 2004.

  1. Dave

    Dave Guest

    I think this is a simple struts question....

    I want to display information on a page in a static way. That is, not
    as part of text elements. I can't find an appropriate struts tag to
    use.

    This what I did find. The form bean will be named the same as the
    "name" attribute of the <form-bean> element in the struts-config.xml.

    So if I have a form bean with 2 string properties, such as str1 and
    str2, I can get the values on my jsp this way:

    <jsp:useBean
    id="DataForm"
    scope="session"
    type="com.mycompany.DataForm" />
    ...
    <p>Str1 : <%=DataForm.getStr1()%></p>
    <p>Str2 : <%=DataForm.getStr2()%></p>

    But that doesn't seem like the right way to do this. I expected some
    kind of special tag that I'll call "getprop":

    <p>Str1 : <html:getprop property="str1"></p>
    <p>Str2 : <html:getprop property="str2"></p>

    What is the right way to do this?
     
    Dave, Jul 13, 2004
    #1
    1. Advertising

  2. Dave

    Murray Guest

    "Dave" <> wrote in message
    news:...
    > I think this is a simple struts question....
    >
    > I want to display information on a page in a static way. That is, not
    > as part of text elements. I can't find an appropriate struts tag to
    > use.
    >
    > This what I did find. The form bean will be named the same as the
    > "name" attribute of the <form-bean> element in the struts-config.xml.
    >
    > So if I have a form bean with 2 string properties, such as str1 and
    > str2, I can get the values on my jsp this way:
    >
    > <jsp:useBean
    > id="DataForm"
    > scope="session"
    > type="com.mycompany.DataForm" />
    > ...
    > <p>Str1 : <%=DataForm.getStr1()%></p>
    > <p>Str2 : <%=DataForm.getStr2()%></p>
    >
    > But that doesn't seem like the right way to do this. I expected some
    > kind of special tag that I'll call "getprop":
    >
    > <p>Str1 : <html:getprop property="str1"></p>
    > <p>Str2 : <html:getprop property="str2"></p>
    >
    > What is the right way to do this?


    <bean:write name="DataForm" property="str1"/>
     
    Murray, Jul 13, 2004
    #2
    1. Advertising

  3. Dave

    Dave Guest

    In article <40f3e814$0$16103$>,
    says...
    > <bean:write name="DataForm" property="str1"/>


    Thank you so much!
     
    Dave, Jul 13, 2004
    #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. Benjamin Stewart

    To bean or not to bean...

    Benjamin Stewart, Jun 30, 2003, in forum: Java
    Replies:
    0
    Views:
    821
    Benjamin Stewart
    Jun 30, 2003
  2. Thomas P. Fuller
    Replies:
    1
    Views:
    4,610
    bitbucket43
    Aug 17, 2004
  3. jill
    Replies:
    5
    Views:
    15,820
  4. Replies:
    0
    Views:
    378
  5. Dave
    Replies:
    2
    Views:
    120
    kaeli
    Jul 13, 2004
Loading...

Share This Page