Ejemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see org.apache.wicket.behavior.Behavior#onComponentTag(org.apache.wicket.Component,
   * org.apache.wicket.markup.ComponentTag)
   */
  @Override
  public void onComponentTag(Component component, ComponentTag tag) {
    super.onComponentTag(component, tag);

    if (!Form.class.isAssignableFrom(component.getClass())) {
      throw new WicketRuntimeException("This behavior is only applicable on a Form component");
    }

    Form<?> form = (Form<?>) component;

    // Retrieve and set form name
    String formName = verifyFormName(form, tag);

    tag.put("onsubmit", "return yav.performCheck('" + formName + "', rules);");

    // Open the Yav script (inlined JavaScript)
    AppendingStringBuffer buffer = new AppendingStringBuffer("<script>\n");
    buffer.append("var rules=new Array();\n");

    // Visit all form components and check for validators (and write the
    // appropriate Yav rules in the current inlined JavaScript)
    form.visitFormComponents(new YavFormComponentVisitor(buffer, form));

    // Build the call to the yav.init with the proper form name
    buffer.append("function yavInit() {\n");
    buffer.append("    yav.init('" + formName + "', rules);\n");
    buffer.append("}\n");

    // Close the Yav script
    buffer.append("</script>\n");

    // Write the generated script into the response
    Response response = RequestCycle.get().getResponse();
    response.write(buffer.toString());
  }
Ejemplo n.º 2
0
 @Override
 public void onUnauthorizedInstantiation(Component component) {
   Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
   if (authentication == null || !authentication.isAuthenticated()) {
     throw new RestartResponseAtInterceptPageException(LoginPage.class);
   } else {
     throw new UnauthorizedInstantiationException(component.getClass());
   }
 }
  /** Render the header from the associated markup file */
  @Override
  public void renderHead(final Component component, HtmlHeaderContainer container) {
    if (!(component instanceof WebMarkupContainer)) {
      throw new WicketRuntimeException(
          Classes.simpleName(component.getClass())
              + " can only be associated with WebMarkupContainer.");
    }

    renderHeadFromAssociatedMarkupFile((WebMarkupContainer) component, container);
  }
Ejemplo n.º 4
0
 @Override
 public void onInstantiation(Component component) {
   final AuthenticatedUser classAnnotation =
       component.getClass().getAnnotation(AuthenticatedUser.class);
   if (classAnnotation != null) {
     if (userService.isUserAnonymous()) {
       throw new RestartResponseException(LoginPage.class);
     } else if (!hasEmail()) {
       throw new RestartResponseException(ProfileEditPage.class);
     }
   }
 }