You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pavlikus <pa...@bk.ru> on 2004/06/21 21:54:42 UTC
Struts-menu question
Hi all.
Sory for a offtopic, but there are no response from struts-menu
mailing list... May be some of you familiar with struts-menu.
I try to add PermissionAdapter to my menu. But method is isAllowed was
never called.
Please point out me my mistakes.
Menu-config:
<Menu name="UserMenu" title="" >
<Item name="user-menu.profile" title="user-menu.profile"
location="EditProfile.do" roles="Foo-Roles" />
<Item name="user-menu.logout" title="user-menu.logout"
location="Logout.do" roles="Foo-Roles" />
</Menu>
Jsp:
<%@ taglib uri="http://struts-menu.sf.net/tag" prefix="menu" %>
<% request.getSession().setAttribute("userMenuAdapter",
new foo.bar.UserMenuPermissionAdapter());
%>
<menu:useMenuDisplayer name="Simple"
bundle="org.apache.struts.action.MESSAGE"
permissions="userMenuAdapter">
<menu:displayMenu name="UserMenu"/>
</menu:useMenuDisplayer>
Adapter:
public class UserMenuPermissionAdapter implements PermissionsAdapter {
private static Log log = LogFactory.getLog(UserMenuPermissionAdapter.class);
public boolean isAllowed(MenuComponent menu) {
log.debug("UserMenuPermissionAdapter - " + menu.getTitle());
return true;
}
...
Method isAllowed is never called. Any advices?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Pulling Punches
Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Niall Pemberton wrote:
>More info on the circumstances would be helpful..
>
>1) How Often - just for one particular Action, for all Actions or somewhere
>in between?
>
>
I'm looking for a generic solution for about 6 to 10 Actions that all
work on a set of objects.
>2) What kind of ActionForms are you using - regular or DynaActionForm?
>
>
Regular
>3) Are you using the validator framework?
>
>
>
No, just validate(...) methods.
>Having said that there are a number of possibilities
>
>1) Put the check in the ActionForm validate method, before you do your other
>validations.
>
>
Problem is, I can't forward from the ActionForm, if an error occurs then
its off to "input" before I could forward in the Action.
>2) Set the validate="false" in the struts-config.xml - Struts won't then
>call the ActionForm's validate() method. You could then do the check in your
>Action and if its OK then call the ActionForm's validate method yourself
>from the Action's execute method. Smething like...
>
> // Check if Stale
> ActionErrors errors = null;
> if (isStale()) {
> errors = new ActionErrors();
> errors.add(....);
> saveErrors(request, errors);
> return mapping.getInputForward();
> }
>
> // Do ActionForm validation
> errors = form.validate(mapping, request);
> if (errors != null && errors.size() > 0)
> saveErrors(request, errors);
> return mapping.getInputForward();
> }
>
>
>
This is probibly the approach I will need to take.
>3) If its something you want to do for every Action you could put the above
>option in a 'base' Action that you extend all your Action's from.
>Alternatively you could implement your own custom RequestProcessor -
>overriding the processValidate() method - you would have to duplicate the
>code to forward to the input though.
>
>
>
Oof, not sure I want to go that far yet.
-thanks!
Mark
Re: Pulling Punches
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
More info on the circumstances would be helpful..
1) How Often - just for one particular Action, for all Actions or somewhere
in between?
2) What kind of ActionForms are you using - regular or DynaActionForm?
3) Are you using the validator framework?
Having said that there are a number of possibilities
1) Put the check in the ActionForm validate method, before you do your other
validations.
2) Set the validate="false" in the struts-config.xml - Struts won't then
call the ActionForm's validate() method. You could then do the check in your
Action and if its OK then call the ActionForm's validate method yourself
from the Action's execute method. Smething like...
// Check if Stale
ActionErrors errors = null;
if (isStale()) {
errors = new ActionErrors();
errors.add(....);
saveErrors(request, errors);
return mapping.getInputForward();
}
// Do ActionForm validation
errors = form.validate(mapping, request);
if (errors != null && errors.size() > 0)
saveErrors(request, errors);
return mapping.getInputForward();
}
3) If its something you want to do for every Action you could put the above
option in a 'base' Action that you extend all your Action's from.
Alternatively you could implement your own custom RequestProcessor -
overriding the processValidate() method - you would have to duplicate the
code to forward to the input though.
Niall
----- Original Message -----
From: "Mark R. Diggory" <md...@latte.harvard.edu>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, June 22, 2004 12:32 AM
Subject: Pulling Punches
> Here's an interesting one for ya.
>
> I have a struts action in which I use the "input" parameter to forward
> back to the jsp when validation errors occur (pretty basic). There is an
> instance where an object could be stale once the browser gets into my
> Actions execute method, when this is encountered the action forwards to
> an error page that provides a message. This way if anyone bookmarks the
> action, I can show something better than a stack trace when they return
> to the page.
>
> My problem is that I get forwarded back to the input form without
> execute occuring and teh stale object being encountered! When returning
> via a bookmark, I get dumped into the JSP designated in the input
> attribute. Is there any way I can execute some code to verify the object
> is not stale BEFORE validation occurs?
>
> What it really boils down to is this. Is there a way I can cause an
> ActionForward before ActionForm.validate occurs?
>
> -Mark
>
>
----------------------------------------------------------------------------
----
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Pulling Punches
Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Here's an interesting one for ya.
I have a struts action in which I use the "input" parameter to forward
back to the jsp when validation errors occur (pretty basic). There is an
instance where an object could be stale once the browser gets into my
Actions execute method, when this is encountered the action forwards to
an error page that provides a message. This way if anyone bookmarks the
action, I can show something better than a stack trace when they return
to the page.
My problem is that I get forwarded back to the input form without
execute occuring and teh stale object being encountered! When returning
via a bookmark, I get dumped into the JSP designated in the input
attribute. Is there any way I can execute some code to verify the object
is not stale BEFORE validation occurs?
What it really boils down to is this. Is there a way I can cause an
ActionForward before ActionForm.validate occurs?
-Mark