neharob / prettyfaces

Automatically exported from code.google.com/p/prettyfaces
0 stars 0 forks source link

Possibility of several UrlAction per UrlMapping #77

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Declare a URLAction in a bean
2. Add another action programmatically like that: 
(myMapping.addAction(myOtherAction);)

What is the expected output? What do you see instead?
Only one action will be used: that declared through the annotation. However it 
could sometimes be useful to have TWO actions per mapping.

What version of PrettyFaces are you using? On what server and version,
version of JSF, and other relevant technologies?
3.1.1 (snapshot from 11 november)

Original issue reported on code.google.com by bal...@gmail.com on 18 Nov 2010 at 6:19

GoogleCodeExporter commented 9 years ago
Hmm... we looked through the code looking to be affected, but couldn't spot the 
issue.
Could you provide a small project (maven?) to reproduce the issue? 

thanks,
dominik

Original comment by dominik....@gmail.com on 18 Nov 2010 at 9:34

GoogleCodeExporter commented 9 years ago
Multiple URL actions are definitively possible. If you are using the annotation 
style configuration you can do this by using the @URLActions annotation like 
this:

@URLActions(actions = {
  @URLAction(mappingId = "myMapping", phaseId = PhaseId.RENDER_RESPONSE),
  @URLAction(mappingId = "otherMapping", phaseId = PhaseId.INVOKE_APPLICATION)
})
public void myAction() {
  // some code
}

But it seems like you are trying to add the second action programmatically, 
correct?
Where do you call myMapping.addAction(myOtherAction)? From a 
ConfigurationPostProcessor?

Original comment by chkalt on 19 Nov 2010 at 6:26

GoogleCodeExporter commented 9 years ago
But it seems like you are trying to add the second action programmatically,
correct?
Yes it is correct.

Where do you call myMapping.addAction(myOtherAction)? From a
ConfigurationPostProcessor?
Yes.

Original comment by bal...@gmail.com on 19 Nov 2010 at 4:23

GoogleCodeExporter commented 9 years ago
I was not able to reproduce this issue. The following 
ConfigurationPostProcessor works as expected:

public class AddActionsConfigPostProcessor implements ConfigurationPostProcessor
{

   @Override
   public PrettyConfig processConfiguration(ServletContext context, PrettyConfig config)
   {
      for(UrlMapping mapping : config.getMappings()) 
      {
         mapping.addAction( new UrlAction("#{welcomeBean.secondAction}") );
      }
      return config;
   }

}

However it is important to understand that this code appends the new action to 
the list of existing actions. This means that the new action will be executed 
after all other actions. If one of the existing actions returns a result (not 
null or void), PrettyFaces will call the NavigationHandler to process this 
outcome. In this case the remaining actions won't be executed and a navigation 
will occur.

Perhaps this is the cause of your problem? In this case you could try to insert 
the action before all others by using something like this:

         mapping.getActions().add(0, new UrlAction("#{welcomeBean.secondAction}") );

Original comment by chkalt on 20 Nov 2010 at 7:06

GoogleCodeExporter commented 9 years ago
It works perfectly! Thanks. Next time I will post on the forum instead of
opening issues.
Thanks a lot!
J.

Original comment by bal...@gmail.com on 20 Nov 2010 at 10:58

GoogleCodeExporter commented 9 years ago

Original comment by chkalt on 20 Nov 2010 at 11:00