Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Running" a method from a bean 2

Status
Not open for further replies.
Feb 4, 2002
792
GB
Hi,

I am new to beans, and have created one, compiled it, and in my jsp page I have used the <jsp:useBean> tag to instantiate the bean. I have then used setProperty to set the properties of the bean as required. However, for the life of me (I have been searching for like 2 hours!) I can't find a way to call the main method from the bean (not "main" as in a method called main - the method I am trying to call is "validate()").

Any help would be most appreciated, even if this is a stupid problem!

Here is the simple page:
Code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page session="true"%>
<html>
    <head><title>PanWebRadius Logon Page</title></head>
    <body>

        <jsp:useBean id="beanLogon" scope="session" class="Beans.RadiusLoginBean" />
        <jsp:setProperty name="beanLogon" property="username" />
        <jsp:setProperty name="beanLogon" property="password" />

     </body>
</html>

tia,

Will
 
i'm not sure if there's a jsp bean tag for calling methods, but you can do it like so using scriptlets:

<%
// use the id you've given the bean
beanLogon.validate();
%>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
The reason why you cannot call a "main" method using the standard jsp tag library is due to whole design methodology of using jsp tags and beans.

Beans are meant for data encapsulation, not for data processing or business logic. For this, you should submit the bean to some kind of action servlet which processes the data.
An example of this taken to another level are MVC2 frameworks such as Struts.

Now this methodology is not to everyone's liking, but it is an explanation of why you cannot do it.

If you feel you still want to do a call to this "main" method, then as jeff said, using scriptlet tags.

--------------------------------------------------
Free Database Connection Pooling Software
 
Hi chaps,

I worked it out myself in the end, but using a script tag like jemminger mentioned.
I feel sedji's post is a little advanced for what I was asking for, but then since I made this post, suddenly what was said makes sense, and Struts and actions are indeed what I am playing with now!
In fact, I am just completeing a piece of code which will likely be added to the sourceforge project SSL-Explorer! It is my first foray into a real-world project, and it uses struts and beans and actions!
Here is the code as I eventually got it working:

Code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page session="true"%>
<html>
    <head><title>PanWebRadius Logon Page</title></head>
    <body>

        <jsp:useBean id="beanLogon" scope="session" class="Beans.RadiusLoginBean">
            <jsp:setProperty name="beanLogon" property="username" />
            <jsp:setProperty name="beanLogon" property="password" />
        </jsp:useBean>
        
        <b><% out.print(beanLogon.validate()); %></b>
        
    </body>
</html>

Currently I have moved away from the bean, because the beans are being used (as suggested) for data encapsulation. The bean I wrote is now embedded in a Java class which is integrated into a proprietary UserDatabase class for the SSL application. I am just ironing out bugs as we speak! :)

Thanks again,

Will
[morning]
 
lol at that jeff ...

Will, glad you got it to work ... you know there is a Struts forum here at TT - forum946

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top