We use Prettyfaces and Rewrite library in our JSF project.

Is there a way how we can reset bean attributes (set them to null) before PrettyFaces sets these attributes' values from query parameters in the URL? I.e. can we call a method on the bean before PrettyFaces sets the values?

1

There are 1 best solutions below

9
Lincoln On

To accomplish this, I believe the simplest way would be to Inject the Bean into a RewriteConfiguration object. You'll need to make sure the priority is overridden such that this provider occurs before the built-in PrettyFaces functionality (I believe -10 should do, but you may need to play with this value):

public class ExampleConfigurationProvider extends HttpConfigurationProvider
{
   @Inject
   private MySessionBean bean;

   @Override
   public int priority()
   {
      return -10;
   }

   @Override
   public Configuration getConfiguration(final ServletContext context)
   {
      return ConfigurationBuilder.begin()
          .addRule()
          .when(Path.matches("/my-path").and(Direction.isInbound()))
          .perform(new HttpOperation() {
             @Override
             public void performHttp(HttpServletRewrite event, EvaluationContext context)
             {
                bean.clearValues();
             }
          });
   }
}

```

Note, the .when() rule can contain any conditions that you want.

There are probably other ways of doing this, but this is the simplest I could think of.