i need advice how recommended way handle twitter bootstrap fields thymeleaf. know recommendations not easy, wrote thoughts , hope can comment it. @ end there concrete questions. first tried fragment shows needed generate
<div th:fragment="textfield"> <div class="control-group" th:classappend="${#fields.haserrors('__${fid}__')}? 'error'"> <label class="control-label" th:for="${fid}" th:text="#{model.__*{class.simplename}__.__${fid}__}+':'"> firstname </label> <div class="controls"> <input type="text" th:class="${inputclass}" th:field="*{__${fid}__}" th:disabled="${disabled}"/> <span class="help-inline" th:if="${#fields.haserrors('__${fid}__')}" th:errors="*{__${fid}__}"></span> </div> </div> </div>
which can used with
<div class="control-group replace" th:include="templates::textfield" th:with="fid='userid'" th:remove="tag"> <label class="control-label replace">benutzer-id</label> <div class="controls replace"> <input type="text" value=""/> </div> </div>
or in short
<div class="control-group replace" th:include="templates::textfield" th:with="fid='userid'" th:remove="tag"/>
it's not flexible input, need checkbox own fragment.
next choose layout-approach:
<div layout:fragment="bsfield"> <div class="control-group" th:classappend="${#fields.haserrors('__${fid}__')}? 'error'"> <label class="control-label" th:for="${fid}" th:text="#{model.__*{class.simplename}__.__${fid}__}+':'"> firstname </label> <div class="controls"> <span layout:fragment="bsinput" th:remove="tag"> <input type="text" class="replace" th:field="*{__${fid}__}" th:disabled="${disabled}"/> </span> <span class="help-inline" th:if="${#fields.haserrors('__${fid}__')}" th:errors="*{__${fid}__}"></span> </div> </div> </div>
which flexible because can define input directly.
i can use shortly with
<div layout:include="templates::bsfield" th:with="fid='firstname'" th:remove="tag"> <div layout:fragment="bsinput"> <input type="text" th:field="*{__${fid}__}" th:disabled="${disabled}"/> </div> </div>
or more prototype style
<div class="control-group" layout:include="templates::bsfield" th:with="fid='lastname'" th:remove="tag"> <label class="control-label" th:remove="all">last name</label> <div class="controls" th:remove="tag"> <div layout:fragment="bsinput"> <input type="text" th:field="*{__${fid}__}" th:disabled="${disabled}"/> </div> </div> </div>
both variants has still lot of boilerplate. think following solution inspired playframework helper.
<input type="text" th:bsfield="firstname" th:disabled="${disabled}"/>
and writing processor creates
<div class="control-group" th:classappend="${#fields.haserrors('${fid}')}? 'error'"> <label class="control-label" th:for="${fid}" th:text="#{model.__*{class.simplename}__.${fid}}+':'"> firstname </label> <div class="controls"> <input type="text" th:class="${inputclass}" th:field="*{${fid}}" th:disabled="${disabled}"/> <span class="help-inline" th:if="${#fields.haserrors('${fid}')}" th:errors="*{${fid}}"></span> </div> </div>
and replace ${fid}
value of bsfield in example "firstname". after thymeleaf should recompute (setrecomputeprocessorsimmediately (true);
) prototype think it's necessary write js-solution.
i'm unsure if clever or misuse of processors. furthermore i'm unsure how time beginner need write such processor. 4 hours realistic or more few days?
would appreciate if can give me hint.
in meantime did it. beginner must calculate 4-8 hours, without junit tests (it looks difficult test processors) , dtd , editor-support. problems had it's difficult reuse existing node after changing attributes. here it's better clone it.
next time think can in 1 or 2 hours.
the experience good, have clean , short code. js-file don't lose prototyping experience.
Comments
Post a Comment