1
I’m developing a web system and I’m having a hard time finishing CRUD. The system is already saving my pacthpanel object, it has equipment registered to this patch. The information is being saved correctly in the database what I need is to bring this equipment information in inputs so that it is possible for the user to edit this information;
*Emphasizing that the registration screen is dynamic, where the user can choose the amount of equipment he wants to register, so, if he registers 10, in the edition is for came the 10.
My patchpanel form
<div class="row">
<form id="formQuantidade" role="form"
action="@{Patchpanels.salvarPatchpanel}" method="post">
<div class="col-lg-6">
<!-- Inicio da primeira coluna -->
<input type="hidden" name="patchpanel.id" value="${p?.id}" />
<div class="form-group">
<label>Nome completo:</label> <input type="text"
name="patchpanel.nome" class="form-control"
value="${flash['patchpanel.nome'] ? flash['patchpanel.nome'] : p?.nome}">
<span class="alert-danger">#{error 'patchpanel.nome' /}</span>
</div>
<div class="form-group">
<label>MAC:</label> <input type="text" id="enderecoMac"
name="patchpanel.mac" class="form-control"
value="${flash['patchpanel.mac'] ? flash['patchpanel.mac'] : p?.mac}">
<span class="alert-danger">#{error 'patchpanel.mac' /}</span>
</div>
<div class="form-group">
<label>Endereço IP:</label><input type="text" id="ipAddress"
name="patchpanel.ip" class="form-control"
value="${flash['patchpanel.ip'] ? flash['patchpanel.ip'] : p?.ip}">
<span class="alert-danger">#{error 'patchpanel.ip' /}</span>
</div>
<div class="form-group">
<label>Torre:</label> <select name="patchpanel.torre.id"
class="form-control">
<span class="alert-danger">#{error 'torre.nome' /}</span> #{list
items:torre, as:'t'}
<option value="${t.id}">${t.nome}</option> #{/list}
</select>
</div>
<div class="form-group">
<label>Status:</label> <select class="form-control"
name="patchpanel.statusPatch"
value="${flash['patchpanel.statusEquipamento'] ? flash['patchpanel.statusEquipamento'] : p?.statusEquipamento}">
<option>Contectado</option>
<option>Desconectado</option>
</select>
</div>
</div>
<div class="col-lg-6">
<!-- inicio da segunda coluna -->
#{ifnot p}
<div class="form-group">
<label>Número de portas:</label> <select id="numporta" type="number"
name="patchpanel.numPortas" class="form-control"
value="${flash['patchpanel.numPortas'] ? flash['patchpanel.numPortas'] : p?.numPortas}"
onchange="geraAlerta(this.value)" required>
<option></option>
<option>5</option>
<option>10</option>
</select> <span class="alert-danger">#{error 'patchpanel.numPortas' /}</span>
</div>
<div class="inputs"></div>
<br> #{/ifnot}
#{list items:p, as:'pathcpanel'}
#{list items:pathcpanel.portas, as:'porta'}
<td><label> Equipamento:</label></br><input type="text" class="form-control" name="porta.descricao" value="${porta.descricao}"></td>
#{/list}
#{/list}
</div>
<div class="col-lg-12">
<input type="submit" class="btn btn-success"
value="${p ? 'Alterar' : 'Cadastrar' }"></input>
<button type="reset" class="btn btn-danger"
onclick="window.location.href='/patchpanels/listagemPatchpanel';">Cancelar</button>
</div>
</form>
My model patch
package models;
@Entity
public class Patchpanel extends Model {
@Required
public String nome;
@Required
public String mac;
@Required
@IPv4Address
public String ip;
@Required
public String numPortas;
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, mappedBy="patchpanel")
public List<Porta> portas;
@ManyToOne
@JoinColumn(name="torre_id")
public Torre torre;
@Enumerated(EnumType.STRING)
public Status status;
@Enumerated(EnumType.STRING)
public StatusEquipamento statusEquipamento;
public Patchpanel() {
status = Status.ATIVO;
statusEquipamento = StatusEquipamento.CONECTADO;
}
}
If you can print the data on a screen you can put this data into the inputs by the attribute
value
.– Laércio Lopes
You can use jstl foreach
– Javeson Yehudi