I forgot, in the example, you also need to include class="form-horizontal" in 
beaneditform declaration,
i.e. 

> <t:beaneditform t:mixins="formhorizontal" class="form-horizontal" 
> labelClass="col-md-3" object="obj"/>


On Oct 20, 2013, at 4:15 PM, Lenny Primak wrote:

> I did some work on a mixin (very preliminary)
> It generates correct markup for form-horizontal layout for beaneditor.
> 
> I will put it into flowlogix module or a separate module under flowlogix when 
> its ready
> -------- Example --------
> <t:beaneditform t:mixins="formhorizontal" labelClass="col-md-3" object="obj"/>
> -------- Code ----------
> package com.flowlogix.website.mixins;
> 
> import com.google.common.base.Function;
> import com.google.common.collect.Collections2;
> import lombok.extern.slf4j.Slf4j;
> import org.apache.tapestry5.BindingConstants;
> import org.apache.tapestry5.MarkupWriter;
> import org.apache.tapestry5.annotations.MixinAfter;
> import org.apache.tapestry5.annotations.Parameter;
> import org.apache.tapestry5.dom.Attribute;
> import org.apache.tapestry5.dom.Element;
> import org.apache.tapestry5.dom.Visitor;
> 
> /**
> *
> * @author lprimak
> */
> @MixinAfter
> @Slf4j
> public class FormHorizontal
> {
>    private @Parameter(defaultPrefix = BindingConstants.LITERAL, value = 
> "col-md-2") String labelClass;
>    private @Parameter(defaultPrefix = BindingConstants.LITERAL, value = 
> "col-md-8") String inputClass;
> 
> 
>    public void afterRender(MarkupWriter mw)
>    {
>        mw.getElement().visit(new HV());
>    }
> 
> 
>    private class HV implements Visitor
>    {
>        @Override
>        public void visit(Element element)
>        {
>            log.debug("EltName: " + element.getName()
>                    + ", attr: " + 
> Collections2.transform(element.getAttributes(), new Function<Attribute, 
> String>()
>            {
>                @Override
>                public String apply(Attribute input)
>                {
>                    return input.getName() + "=" + input.getValue();
>                }
>            }));
> 
>            if(element.getName().equals("label"))
>            {
>                String classAttr = element.getAttribute("class");
>                if(classAttr.contains("control-label"))
>                {
>                    element.attribute("class", labelClass);
>                    labelProcessed = true;
>                }
>            }            
>            else if(labelProcessed)
>            {
>                labelProcessed = false;
>                element.wrap("div", "class", inputClass);
>            }
>        }
> 
>        private boolean labelProcessed = false;
>    }
> }
> 
> --------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to