schraal / tomahawk-facelets

Facelets support for Apache MyFaces Tomahawk
Apache License 2.0
0 stars 0 forks source link

AliasBean TagHandler duplicates components #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The AliasBean TagHandler duplicates its content, if a valiation error 
occours and the current page is rerendered. It shoukd extend the 
ComponentHandler class, and not implement the apply() method by itself.

Original issue reported on code.google.com by 42.be...@gmail.com on 4 Mar 2008 at 5:01

GoogleCodeExporter commented 9 years ago
It should be like this:

import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentTag;

import org.apache.myfaces.custom.aliasbean.AliasBean;

import ch.bedag.common.web.component.taglib.facelets.BaseComponentHandler;

import com.sun.facelets.FaceletContext;
import com.sun.facelets.tag.MetaRuleset;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.jsf.ComponentConfig;

/**
 * Handler for AliasBean Component.
 * 
 * @author $Author: mse $
 * @version $Date: 2008/03/04 18:12:27 $
 */
public class AliasBeanHandler extends BaseComponentHandler {

    private TagAttribute valueAttr;

    private TagAttribute aliasAttr;

    public AliasBeanHandler(ComponentConfig aConfig) {
        super(aConfig);

        valueAttr = getRequiredAttribute("value");
        aliasAttr = getRequiredAttribute("alias");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected MetaRuleset createMetaRuleset(Class aClass) {
        MetaRuleset theRules = super.createMetaRuleset(aClass);
        theRules = theRules.ignore("value");
        theRules = theRules.ignore("alias");
        return theRules;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onComponentCreated(FaceletContext aContext, UIComponent 
aComponent, UIComponent aParent) {
        super.onComponentCreated(aContext, aComponent, aParent);

        AliasBean theComponent = (AliasBean) aComponent;

        Application app = aContext.getFacesContext().getApplication();

        String theValue = valueAttr.getValue();
        if (UIComponentTag.isValueReference(theValue)) {
            theComponent.setValueBinding("value", app.createValueBinding
(valueAttr.getValue()));
        } else {
            theComponent.setValue(theValue);
        }

        String theAlias = aliasAttr.getValue();
        if (UIComponentTag.isValueReference(theAlias)) {
            theComponent.setValueBinding("alias", app.createValueBinding
(aliasAttr.getValue()));
        } else {
            theComponent.setAlias(theAlias);
        }
    }
}

Original comment by 42.be...@gmail.com on 4 Mar 2008 at 6:22

GoogleCodeExporter commented 9 years ago
Hi Mirko,

Can you explain to me what

ch.bedag.common.web.component.taglib.facelets.BaseComponentHandler

is? It does not seam to be a standard Tomahawk or Facelets dependency.

Original comment by hilbert....@gmail.com on 12 May 2008 at 1:33

GoogleCodeExporter commented 9 years ago
Hi

Basically, you can inherit from the com.sun.facelets.tag.jsf.ComponentHandler 
instead
of the ch.bedag.... class. It has the same effect than using the subclass from 
our
companies component handler framework. The important thing is that you have to 
use the
onComponentCreated method the way described above to make sure that the 
taghandler
does not duplicate the component tree.

Regards
Mirko

Original comment by 42.be...@gmail.com on 13 May 2008 at 7:52

GoogleCodeExporter commented 9 years ago
I also get child component duplication when an immediate CommandButton pointing 
to
the current page is used.

Switching to Mirko's tag handler solved this problem.

Original comment by adrian.m...@bedag.ch on 18 Feb 2009 at 4:40

GoogleCodeExporter commented 9 years ago

Original comment by hilbert....@gmail.com on 31 Mar 2010 at 1:50

GoogleCodeExporter commented 9 years ago

Original comment by hilbert....@gmail.com on 31 Mar 2010 at 1:50