1 15 package org.apache.tapestry.vlib; 16 17 import org.apache.tapestry.PageRedirectException; 18 import org.apache.tapestry.callback.PageCallback; 19 import org.apache.tapestry.event.PageEvent; 20 import org.apache.tapestry.event.PageValidateListener; 21 import org.apache.tapestry.form.IFormComponent; 22 import org.apache.tapestry.html.BasePage; 23 import org.apache.tapestry.valid.IValidationDelegate; 24 import org.apache.tapestry.vlib.pages.Login; 25 26 35 36 public abstract class Protected extends BasePage implements IErrorProperty, PageValidateListener 37 { 38 private IValidationDelegate _validationDelegate; 39 40 public void initialize() 41 { 42 _validationDelegate = null; 43 } 44 45 public IValidationDelegate getValidationDelegate() 46 { 47 if (_validationDelegate == null) 48 _validationDelegate = new VirtualLibraryDelegate(); 49 50 return _validationDelegate; 51 } 52 53 protected void setErrorField(String componentId, String message) 54 { 55 IFormComponent component = (IFormComponent) getComponent(componentId); 56 57 IValidationDelegate delegate = getValidationDelegate(); 58 59 delegate.setFormComponent(component); 60 delegate.record(message, null); 61 } 62 63 67 68 protected boolean isInError() 69 { 70 return getError() != null || getValidationDelegate().getHasErrors(); 71 } 72 73 79 80 public void pageValidate(PageEvent event) 81 { 82 Visit visit = (Visit) getVisit(); 83 84 if (visit != null && visit.isUserLoggedIn()) 85 return; 86 87 89 Login login = (Login) getRequestCycle().getPage("Login"); 90 91 login.setCallback(new PageCallback(this)); 92 93 throw new PageRedirectException(login); 94 } 95 } | Popular Tags |