stay at page rule

Splash Forums Rewrite Users stay at page rule

This topic contains 5 replies, has 2 voices, and was last updated by  Christian Kaltepoth 1 year, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26580

    Adrian
    Participant

    Hi

    I would like to write a rule so that the user stays at the page if a certain condition is true. Otherwise he gets redirected as requested.

    What I’ve tried but is not really working was the following:

    @Override
    	public Configuration getConfiguration(final ServletContext context) {
    		return ConfigurationBuilder.begin().addRule().when(new HttpCondition() {
    			public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {
    				HttpSession session = event.getRequest().getSession(false);
    				if (session != null) {
    //get the session scoped spring bean and check condition					
    UtilBean utilBean = (UtilBean) event.getRequest().getSession().getAttribute("utilBean");
    					if (utilBean != null && utilBean.isObjectChanged()) {
    						return true;
    					}
    				}
    				return false;
    			}
    		}).perform(Lifecycle.handled());
    
    	}

    Any suggestions how to solve that problem?

    #26583

    Could you describe your usecase a bit more? Do you want to forward every page request to a specific view if some condition is true?

    #26588

    Adrian
    Participant

    the usecase is: if a user modifies something in the RIA the condition goes to true. If he navigates to another page in the application without saving then he schould get not redirected to this page. instead he should stay on the same page and a hint is shown in the application that not everything was saved.

    so the rule should not forward if condition is true.
    we have prettyfaces in the background, so something like a dynamicviewid returnvalue “pretty:” is that what i’m looking for.

    #26650

    Something like this could work:

    
    .addRule()
    .when(Direction.isInbound().and(Not.any(Path.matches("/somepage")))
        .and(new HttpCondition() {
      public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {
        // your custom check here
      }
    }))
    .perform(Redirect.temporary("/somepage"));
    
    #26652

    Adrian
    Participant

    Does a variable exists where I can get the current page and another with the page where the user wants to navigate? (e.g commingFrom / goingTo)

    The problem is that my rule should apply to about 20 pages and even if I create a rule for every page your solution will not work as long as I can decide if a real url page change is happening.

    if the variable exist I could do a rule like

    .addRule()
    .when(Direction.isInbound().and(!commingFrom.equals(goingTo)))
        .and(new HttpCondition() {
      public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {
        // your custom check here
      }
    }))
    .perform(Redirect.temporary(commingFrom));

    So that the rule is active if a page change happens and the condition is true. Then he gets redirected to the commingFrom page. If condition is false he gets redirected to the goingTo page.

    #26656

    There is no commingFrom / goingTo because Rewrite processes individual requests. There is only a “requested URL”.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Comments are closed.