About Question enthuware.jwpv6.2.944 :

Moderator: admin

Post Reply
ETS User

About Question enthuware.jwpv6.2.944 :

Post by ETS User »

This answer on this question is wrong. It will not compile because variable account is not defined.

Code: Select all

<html>
    <body>
    <h1>Simple Bean Usage</h1>
    <% 
        pageContext.setAttribute("account", new com.enthuware.jwebplus.Account(1, "Bobby", 1000.0));
    %>
    
    Account Name is : 
    <jsp:useBean id="account" class="com.enthuware.jwebplus.Account">
        <jsp:setProperty name="account" property="name" param="name"/>
    </jsp:useBean>       
    <%=account.getName()%>
    </body>
</html>

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.944 :

Post by admin »

It works fine. useBean defines the variable.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

ETS User

Re: About Question enthuware.jwpv6.2.944 :

Post by ETS User »

Indeed you are right. I wasn't aware that the variable becomes available after the useBean.

That is good to know because it also means that the following will not compile, due to
a duplicate variable "account".

Code: Select all

<%
Account account = new Account();
%>
<jsp:useBean id="account" class="Account"></jsp:useBean>
Thanks!

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.944 :

Post by himaiMinh »

But when I change the pageContext into request , it prints out "Crazy".

Code: Select all

 <%request.setAttribute("account", new com.nullhaus.Account(1,"Bobby", 1000.0));%>
          Account Name is :     <jsp:useBean id="account" class="com.nullhaus.Account">      
                <jsp:setProperty name="account" property="name" param="name"/>    
              </jsp:useBean>           
              <%=account.getName()%> 
  

It seems to me that the account instance has not been created after request.setAttribute(...)

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests