java - Is it possible encapulate spring form tags inside custom tags? (see update 1) -
in current spring project, create follow custom tag define form:
public class mainformtag extends tagsupport { /** * */ private static final long serialversionuid = 1l; private string action; private string classe; public void dotag() throws ioexception { jspwriter out = pagecontext.getout(); out.println("<form method='post' action='"+action+"'></form>"); } @override public int dostarttag() throws jspexception { return eval_body_include; } @override public int doendtag() { return eval_page; } } this tag used way:
<c:url value="/${entity}/cadastra" var="cadastra"/> <custom:mainform action="${cadastra}" classe="${command['class'].simplename}"> <button type="submit" class="btn btn-lg btn-primary">cadastrar</button> </custom:mainform> but when deploy application , open page whit form, nothing displayed in page. doing wrong here?
my customtag.tld this:
<?xml version="1.0" encoding="utf-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"> <tlib-version>1.0</tlib-version> <short-name>custom</short-name> <uri>/web-inf/customtag</uri> <tag> <name>mainform</name> <tag-class>com.spring.loja.config.taglib.form.mainformtag</tag-class> <attribute> <name>action</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>classe</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>input</name> <tag-class>com.spring.loja.config.taglib.form_control.inputtag</tag-class> <attribute> <name>ordem</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>select</name> <tag-class>com.spring.loja.config.taglib.form_control.selecttag</tag-class> <attribute> <name>ordem</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>embedselect</name> <tag-class>com.spring.loja.config.taglib.form_control.embedselecttag</tag-class> <attribute> <name>ordem</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>textarea</name> <tag-class>com.spring.loja.config.taglib.form_control.textareatag</tag-class> <attribute> <name>ordem</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>checkbox</name> <tag-class>com.spring.loja.config.taglib.form_control.checkboxtag</tag-class> <attribute> <name>ordem</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>label</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>radiobutton</name> <tag-class>com.spring.loja.config.taglib.form_control.radiobuttontag</tag-class> <attribute> <name>ordem</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>label</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib> update 1
i solve problem described above replacing method dotag pair dostarttag , doendtag. have question: possible use spring form tags inside custom tag class? in way, application must transform custom tag in spring form tag , last 1 in final form tag delivered browser.
the methods, if approach possible, that:
public int dostarttag() throws jspexception { try { jspwriter out = pagecontext.getout(); out.println("<form:form method='post' action='"+action+"'>"); } catch (ioexception e) { throw new jspexception("error: " + e.getmessage()); } return eval_body_include; } public int doendtag() throws jspexception { try { jspwriter out = pagecontext.getout(); out.println("</form:form>"); } catch (ioexception e) { throw new jspexception("error: " + e.getmessage()); } return eval_page; }
Comments
Post a Comment