2
I am creating a web application that registers employees,and in this register there is an option to upload photo to link to profile, but when registering null arrives in the bank. Can someone help me?
This is my entity:
public class Agente extends Model{
@Required
@Expose
public String nome;
@Required
public String funcao;
@Required
@MinSize(6)
public String login;
@MinSize(6)
@MaxSize(15)
public String senha;
@Required
@Email
public String email;
public Blob foto;
@Enumerated(EnumType.STRING)
public Status status;
public Agente() {
status = Status.ATIVO;
}
}
My Register Controller:
public static void cadastrarFuncionarios(@Valid Agente funcionario, String senha) throws Exception {
Agente funcionarioBanco = Agente.find("email = ? or login = ?", funcionario.email, funcionario.login).first();
if (funcionario.id == null) {
if (funcionarioBanco != null && funcionarioBanco.id != funcionarioBanco.id && funcionarioBanco.foto == null) {
validation.addError("funcionario.email", "E-mail já existente");
validation.addError("funcionario.login", "Usuário já existente");
validation.addError("funcionario.foto", "Imagem já cadastrada");
}
if (validation.hasErrors() || !funcionario.senha.equals(senha)) {
validation.addError("funcionario.senha", "Senha não corresponde");
params.flash();
validation.keep();
form();
}
if (funcionario.foto == null && funcionario.id != null) {
Agente n = Agente.findById(funcionario.id);
if (n.foto.exists()) {
funcionario.foto = n.foto;
}
}
funcionario.senha = Crypto.passwordHash(senha);
validation.valid("cadastrado com sucesso");
funcionario.save();
session.get("usuarioLogado");
listarFuncionarios(null);
}
}
and the responsible div for capturing the image in html:
<div class="form-group">
<label>Adicionar foto do perfil:</label> <input type="file" name="funcionario.foto" class="form-control">
</div>
exit:
@76gk5ei72 funcios.pulpitrock.jpg action not found
Action not found Action funcionarios.pulpitrock.jpg could not be found. Error raised is Controller controllers.funcionarios.pulpitrock not found play.exceptions.ActionNotFoundException: Action funcionarios.pulpitrock.jpg not found at
play.mvc.Actioninvoker.getActionMethod(Actioninvoker.java:578) at play.mvc.Actioninvoker.resolve(Actioninvoker.java:84) at Invocation.HTTP Request(Play!) Caused by: java.lang.Exception: Controller controllers.funcionarios.pulpitrock not found ... 3 more
Ever tried to use a Try catch to check what happens?
– Theotonio
it displays this: Action employees.pulpitrock.jpg could not be found. Error Raised is Controller controllers.funcionarios.pulpitrock not found
– Tecnologia da Net
Add this attribute to your form
enctype="multipart/form-data"
and in your controller the file will not come as attribute of your model it will be in the context of the request... you will have to save in a server directory or the file blob in the database.– Leandro Angelo