• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saveMessages not visible

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a bean called LoginBean that performs extensive validation of the user.

LoginBean has an instance method called validateUser which is called from my Action Class.

Question: Within a method of LoginBean, why is Action.saveMessages(request, messages) not visible? I see from the Docs that saveMessages is protected. But, even if I have LoginBean extend Action, then saveMessages still isn't visible. I don't believe my LoginBean should extend Action anyway, and yet I do believe my LoginBean should be able to add ActionMessages to the request object. Where am I haywire?

My bigger picture is, if the instance of LoginBean, called loginBean, detects a particular error, then it will create and throw a custom Exception, called HrDbNotFoundException. I have a Global Exception Handler defined in the config file to send the exception somewhere where the ActionMessage(s) can be printed.

Thanks.

Matt

package loginPackage;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import exception.HrDbNotFoundException;

public class LoginBean
{
public boolean validateUser(String username,
String password,
HttpServletRequest request)
throws HrDbNotFoundException {

//this is stripped down code

try
{
//some validating
}
catch (SQLException e) {
if (("... ... ... ...").equals(e.getMessage())) {
System.out.println("Houston, we can't find the database");
ActionMessages messages = new ActionMessages();
messages.add("message1", new ActionMessage("Houston, we have an exception"));
org.apache.struts.action.Action.saveMessages(request, messages);
throw new HrDbNotFoundException();
}
}
return true;
}
}
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

matt love wrote:I have a bean called LoginBean that performs extensive validation of the user.

LoginBean has an instance method called validateUser which is called from my Action Class.

Question: Within a method of LoginBean, why is Action.saveMessages(request, messages) not visible? I see from the Docs that saveMessages is protected. But, even if I have LoginBean extend Action, then saveMessages still isn't visible. I don't believe my LoginBean should extend Action anyway, and yet I do believe my LoginBean should be able to add ActionMessages to the request object. Where am I haywire?

My bigger picture is, if the instance of LoginBean, called loginBean, detects a particular error, then it will create and throw a custom Exception, called HrDbNotFoundException. I have a Global Exception Handler defined in the config file to send the exception somewhere where the ActionMessage(s) can be printed.

Thanks.

Matt




saveMessage isn't a static method and you are trying to call it as a static method of Action. you should instead be calling it on your specific instance of action.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
matt love
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim (and Bear).

The compiler limits what I can do. My preference was to pass my ActionClass object as "this" to my bean and then in my bean obtain saveMessages from my passed ActionClass object. But that didn't work as saveMessages wasn't visible on that passed object.

Would you please tell me why that is?

So what I think I'll do is pass an ActionMessages object to the bean and when control returns to my Action object I will add ActionMessages to the request.

Is this considered "good Struts form"?

Thanks again.

Matt

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic