java - Retrieve an annotated field from a class in the view -
in current spring project, atributes entity classes have annotations indicate type of form control should used data input, this:
@column(name = "login", unique=true) @order(value=1) @input(name="login") private string login; @column(name = "senha") @order(value=2) @input(type="password", name="senha") private string senha; @column(name="nome") @order(value=3) @input(name="nome") private string nome; @column(name="sobrenome") @order(value=4) @input(name="sobrenome") private string sobrenome; @column(name="email") @order(value=5) @input(name="email") private string email;
and have custom tags should read atributes of annotations , add page correct tag, that:
public class inputtag extends tagsupport { /** * */ private static final long serialversionuid = 1l; public void dotag() throws ioexception, nosuchfieldexception, securityexception { jspwriter out = pagecontext.getout(); string name = this.getname(); string type = this.gettype(); string pattern = this.getpattern(); if(type == null) { if(pattern == "") { out.println("<form:input path=\""+name+"\" class=\"form-control\"/>"); } else { out.println("<form:input path=\""+name+"\" class=\"form-control valida\" pattern=\""+pattern+"\"/>"); } } else { if(pattern == "") { out.println("<form:input path=\""+name+"\" type=\""+type+"\" class=\"form-control\"/>"); } else { out.println("<form:input path=\""+name+"\" type=\""+type+"\" class=\"form-control valida\" pattern=\""+pattern+"\"/>"); } } } ... }
the getter methods tag class have format:
private string getname() throws nosuchfieldexception, securityexception { field field = null; annotation annotation = field.getannotation(input.class); input inputannotation = (input) annotation; string name = inputannotation.name(); return name; }
what need right it's way of store in variable field
field want add page. know method if inside entity class (something getclass().getfield("<nome>")
), how access information tag class?
the view mapped in controller way:
@requestmapping(value="cadastra") @preauthorize("haspermission(#user, 'cadastra_'+#this.this.name)") public string cadastra(model model) throws instantiationexception, illegalaccessexception { model.addattribute("command", this.entity.newinstance()); return "private/cadastrar"; }
and jsp code in moment it's (just basic structure):
<c:url value="/${entity}/cadastra" var="cadastra"/> <form:form method="post" action="${cadastra}" class="form" enctype="multipart/form-data"> <button type="submit" class="btn btn-lg btn-primary">cadastrar</button> </form:form>
anyone knows way accomplish this?
Comments
Post a Comment