Newbie question for struts

Discussion in 'Java' started by Hannes Heckner, Sep 8, 2004.

  1. Hello,

    I have the following code in my otherwise fully functional jsp:

    <% String test = "Hello World"; %>
    <logic:present name="test">
    here is hello world
    </logic:present>

    This will never show "here is hello world
    Why?

    Suggestion:
    Because test is no bean

    What I am trying to accomplish is this:

    <%MyBean bean = myForm.getBean() %>

    it is possible in my application that bean is null
    so if I use

    <bean:write name="bean" property"someting"/>

    I will get a NPE

    so I tried to use

    <logic:present name="bean"/>
    Hurray it is here
    <bean:write name="bean" property"something"/>
    </logic:present>

    with the same effect that even if the bean is there there is no output


    Any tips on this one?

    Best regards,
    Hannes
     
    Hannes Heckner, Sep 8, 2004
    #1
    1. Advertising

  2. Hannes Heckner

    jungi Guest

    Hannes Heckner wrote:
    > Hello,


    hi,

    > I have the following code in my otherwise fully functional jsp:
    >
    > <% String test = "Hello World"; %>


    add <% pageContext.setAttribute("test", test, PageContext.PAGE_SCOPE); %>
    here...

    > <logic:present name="test">
    > here is hello world
    > </logic:present>



    >
    > This will never show "here is hello world
    > Why?


    Because there's nothing (not only bean) with name "test" presented in
    page, request, session nor application scope see eg.
    http://struts.apache.org/api/org/apache/struts/taglib/bean/package-summary.html#package_description
    (bottom)

    --jungi

    >
    > Suggestion:
    > Because test is no bean
    >
    > What I am trying to accomplish is this:
    >
    > <%MyBean bean = myForm.getBean() %>
    >
    > it is possible in my application that bean is null
    > so if I use
    >
    > <bean:write name="bean" property"someting"/>
    >
    > I will get a NPE
    >
    > so I tried to use
    >
    > <logic:present name="bean"/>
    > Hurray it is here
    > <bean:write name="bean" property"something"/>
    > </logic:present>
    >
    > with the same effect that even if the bean is there there is no output
    >
    >
    > Any tips on this one?
    >
    > Best regards,
    > Hannes
     
    jungi, Sep 8, 2004
    #2
    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. Katie Wright
    Replies:
    8
    Views:
    4,310
    Andrea Desole
    Jan 7, 2005
  2. Jason Us
    Replies:
    0
    Views:
    1,008
    Jason Us
    Oct 4, 2003
  3. jc1771
    Replies:
    0
    Views:
    422
    jc1771
    Dec 28, 2003
  4. sin
    Replies:
    3
    Views:
    739
    Sudsy
    Feb 22, 2004
  5. Pratap Das
    Replies:
    2
    Views:
    2,058
    Pratap Das
    Apr 5, 2004
Loading...

Share This Page