Define Attribute from radiobutton JSP

1

I am putting together a generic form for registration of individuals and legal entities and the definition starts from two RadioButton's that changes the fields, after they are filled they are sent to a Servlet and then to a DAO class, the form has different CPF fields for PF and CNPJ for PJ, I have a condition in Servlet that needs to validate the selected type to be able to play the fields in class Usuario() and I want to know how can I validate this in JSP from the radio button?

Basic structure:

 <form>
    <!-- Tipo de Cadastro -->                                    
    <input id="radiopf" type="radio" name="Type" checked value="pessoaPF">
    <label for="radiopf">Pessoa Fisica</label>            
    <input id="radiopj" type="radio" name="Type" value="pessoaPJ"> 
    <label for="radiopj">Pessoa Juridica</label>
 </form>

 <!-- Formulário de Cadastro -->
 <form id="frm" name="FormCadastro" action="Controle" method="POST"> 
   <fieldset id = "PF">
       <!-- Campos Pessoa Física -->
   </fieldset>

   <fieldset id = "PJ">
       <!-- Campos Pessoa Jurídica-->
   </fieldset>
   <input type="submit" value="Gravar" name="Cadastrar" onclick="return Validate();" />
 </form>
is a validation in Validate(); made before sending data to JavaScript checks data type, size, formatting, null fields, etc.

strong> Servlet is the Controle that receives data via Servlet to send to class request.getParameter() .

    
asked by anonymous 02.11.2015 / 19:04

1 answer

1

I was able to ...

//html dentro do mesmo <form id="frm"></form>
<input id="radiopf" type="radio" name="Type" checked value="pessoaPF">
<input id="radiopf" type="radio" name="Type" value="pessoaPJ">

//Servlet
if(request.getParameter("Type") != null){
    if(request.getParameter("Type").equals("pessoaPF")) {
         //Atribuição Pessoa Física dentro da classe Usuario();
    }
    if(request.getParameter("Type").equals("pessoaPJ")) {
         //Atribuição Pessoa Jurídica dentro da classe Usuario();
    }
 }
    
02.11.2015 / 23:38