wood burning stoves 2.0*
The moose likes Struts and the fly likes struts2 newbie: (1) how to validate without xml & (2) how to have a dispatchAction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 newbie: (1) how to validate without xml & (2) how to have a dispatchAction?" Watch "struts2 newbie: (1) how to validate without xml & (2) how to have a dispatchAction?" New topic
Author

struts2 newbie: (1) how to validate without xml & (2) how to have a dispatchAction?

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
hey,

Just started using struts2, my first reaction is WOW...the 'interception' is a great idea and finally the struts-config doesn't have the size of the bible :-)

Anyway, since this is my first-dummy-application, I'm struggling with the following:

1. Assuming I have a form (myusername, mypassword) and I would like to verify that the user has input the information - is there a way to do that without the XXXX-validation.xml? if so how?

2. [assuming] I have 10 buttons on the screen, in what way can I assign a dispatchAction?

I have something like this:



say I wish button.doA to do actionA() and button.doB to do actionB()...?

I realized that the

public String intercept(ActionInvocation actionInvocation) throws Exception
{
.
.
actionInvocation.invoke() runs the execute of the Action.

thanks for any pointers
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Regarding validation without XML, you can use annotations instead. See this link for more information.

Regarding DispatchAction: Since in Struts2 you can specify a different action for each submit button, any action class can perform the function of the Struts 1 DispatchAction.
Example:
struts.xml

Login action class

Login.jsp


Merrill
Consultant, Sima Solutions
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Thank you Merrill!

Both are working fine for me!

One issue still remain: I realized that the 'compiler compliance level' suppose to be 5 (for the @ annotation and others). I set my application as level 5 and @ annotation works fine. Problem is that I have this annoying red X on the project and the "Java Resources folder"- signaling that something is wrong (and yet it's working).

Just to eliminate my paranoia- why is it like this and how can I remove it?

1. I did clean on the project, I refresh, I restarted
2. In the project's Libraries I have JRE System Library [jre1.5.0_10]


Thank you
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Whenever you get a red "X" in Eclipse, it should show you the reason for the problem in the tasks or problems view. If you see what the problem is, but still don't know how to solve it, post it here.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Solved!

problem:
Java compiler level does not match the version of the installed Java project facet

Solution:
Right click Project --> Properties --> Project Facets
and changed the Java version to 5.0

Thank you Merrill!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 newbie: (1) how to validate without xml & (2) how to have a dispatchAction?
 
Similar Threads
Struts2 Issue with localization: Messages not picked up from properties file for forward actions.
struts2: what kicks in first- the interceptors or the form's validation?
How to change the default label style in Struts2?
Struts2 Input Validation using Annotations
pass values between pages using Struts2