Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2008, 2009, 2010 The Apache Software Foundation
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 package org.apache.tapestry5.corelib.components;
A FormFragment is a portion of a Form that may be selectively displayed. Form elements inside a FormFragment will automatically bypass validation when the fragment is invisible. The trick is to also bypass server-side form processing for such fields when the form is submitted; client-side logic "removes" the form data for the fragment if it is invisible when the form is submitted; alternately, client-side logic can simply remove the form fragment element (including its visible and hidden fields) to prevent server-side processing.

The client-side element will now listen to two new event defined by client-side constants:

Change the visiblity as per the event memo's visibility property. When the visiblity changes, the correct animation is executed.
Hides the element, then removes it from the DOM entirely.

 public class FormFragment implements ClientElement
Determines if the fragment is initially visible or initially invisible (the default). This is only used when rendering; when the form is submitted, the hidden field value is used to determine whether the elements within the fragment should be processed (or ignored if still invisible).
     private boolean visible;

If true, then the fragment submits the values from fields it contains even if the fragment is not visible. The default is to omit values from fields when the enclosing fragment is non visible.

     private boolean alwaysSubmit;

Name of a function on the client-side Tapestry.ElementEffect object that is invoked to make the fragment visible. If not specified, then the default "slidedown" function is used.
     @Parameter(defaultPrefix = .)
     private String show;

Name of a function on the client-side Tapestry.ElementEffect object that is invoked when the fragment is to be hidden. If not specified, the default "slideup" function is used.
     @Parameter(defaultPrefix = .)
     private String hide;

The element to render for each iteration of the loop. The default comes from the template, or "div" if the template did not specific an element.
     @Parameter(defaultPrefix = .)
     private String element;

If bound, then the id attribute of the rendered element will be this exact value. If not bound, then a unique id is generated for the element.
    @Parameter(name = "id", defaultPrefix = .)
    private String idParameter;
    private Environment environment;
    private ComponentResources resources;
    private String clientId;
    private Logger logger;
        return .getElementName("div");

Renders a <div> tag and provides an override of the environmental.
    void beginRender(MarkupWriter writer)
        FormSupport formSupport = .peekRequired(FormSupport.class);
         = new HiddenFieldPositioner(writer);
        Element element = writer.element(this."id");
        if (!)
        // Here's the magic of environmentals ... we can create a wrapper around
        // the normal FormSupport environmental that intercepts some of the behavior.
        // Here we're setting aside all the actions inside the FormFragment so that we
        // can control whether those actions occur when the form is submitted.
        FormSupport override = new FormSupportAdapter(formSupport)
            public <T> void store(T componentComponentAction<T> action)
            public <T> void storeAndExecute(T componentComponentAction<T> action)
        // Tada! Now all the enclosed components will use our override of FormSupport,
        // until we pop it off.

Closes the <div> tag and pops off the environmental override.

    void afterRender(MarkupWriter writer)
        "id" + "-hidden",
        writer.end(); // div
    public String getClientId()
        return ;
New to GrepCode? Check out our FAQ X