You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Hasan Çelik <ha...@berkadem.com> on 2014/09/21 01:58:56 UTC
how to use PropertyModel for saving image to database
hi,
i have a file upload process for image.
fileupload.java
https://gist.github.com/cortix/9079660
User1.java
https://gist.github.com/cortix/f5fbc0a137d6acfa9b40
fileupload.html
https://gist.github.com/cortix/9082148
i got this error
https://gist.github.com/cortix/9079743
...
final FileUploadField fileUpload = new FileUploadField("fileUpload",new
PropertyModel(user1, "photo"));
form.add(fileUpload);
...
i think i should change my ProperyModel or the method for images to save
database because in my pojo class my object type is byte[]... When i use
this way, i get error... i am thinking if this PropertyModel change, i can
fix this problem but i don't know how can i use this PropertyModel for byte
type..
Web Site : www.berkadem.com
E-mail: hasancelik@berkadem.com
Phone: +90 312 473 38 86
Mobile Phone: +90 544 640 96 25
Address : Öveçler 4. Cadde 1325.sokak No:5/1 Çankaya ANKARA
Re: how to use PropertyModel for saving image to database
Posted by hasan çelik <hs...@gmail.com>.
only i can use your saying this way,
final FileUploadField fileUploadField = new FileUploadField("fileUpload",
new IModel<List<FileUpload>>() {
public List<FileUpload> getObject() {
return null;
}
public void setObject(List<FileUpload> object) {
}
public void detach() {
}
});
because i am getting error "java.lang.NullPointerException" when i use
Model<FileUpload>(),
anyway, i didnt understand :( only i want to hold my pojo class information
into FileUploadField...
the solution works when i use diffrent object type like these
final TextField email = new TextField("email", new
PropertyModel<String>(user1, "email"));
email.setRequired(true);
email.add(EmailAddressValidator.getInstance());
form.add(email);
final PasswordTextField password = new PasswordTextField("password", new
PropertyModel<String>(user1, "password"));
password.setRequired(true);
form.add(password);
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-use-PropertyModel-for-saving-image-to-database-tp4667580p4667586.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to use PropertyModel for saving image to database
Posted by hasan çelik <hs...@gmail.com>.
Hi Andrea,
i have tried your saying again and solved the problem :) thank you so
much...
the solution is,
final FileUploadField fileUploadField = new FileUploadField("fileUpload",
new IModel<List<FileUpload>>() {
public List<FileUpload> getObject() {
return null;
}
public void setObject(List<FileUpload> object) {
}
public void detach() {
}
});
form.add(fileUploadField);
....
...
.....
AjaxButton submit = new AjaxButton("submit") {
@Override
protected void onError(AjaxRequestTarget target1, Form<?> form)
{
feedbackPanel.setVisible(true);
super.onError(target1, form);
target1.add(wrapper);
}
@Override
protected void onSubmit(AjaxRequestTarget ajaxRequestTarget,
Form<?> form) {
user1.setPhoto(fileUploadField.getFileUpload().getBytes());
<-----important
user1Dao.save(user1);
ajaxRequestTarget.add(wrapper);
}
};
form.add(submit);
wrapper.add(form);
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-use-PropertyModel-for-saving-image-to-database-tp4667580p4667612.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to use PropertyModel for saving image to database
Posted by Andrea Del Bene <an...@gmail.com>.
You can try something like this:
FileUploadField fileUpload = new FileUploadField("fileUpload",new
Model<FileUpload>());
form.add(fileUpload);
...
AjaxButton submit = new AjaxButton("submit") {
//onError
@Override
protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
user1.setConsultantApproval("");
user1.setPhoto(fileUpload.getFileUpload().getBytes());
user1Dao.save(user1);
ajaxRequestTarget.add(wrapper);
}
};
> Can you show an example using with (user1, "photo")....because i want to wrap
> my pojo class(User1.java) information with FileUploadField
>
> Thank you again your answer :)
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-use-PropertyModel-for-saving-image-to-database-tp4667580p4667583.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to use PropertyModel for saving image to database
Posted by hasan çelik <hs...@gmail.com>.
Can you show an example using with (user1, "photo")....because i want to wrap
my pojo class(User1.java) information with FileUploadField
Thank you again your answer :)
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-use-PropertyModel-for-saving-image-to-database-tp4667580p4667583.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to use PropertyModel for saving image to database
Posted by Sven Meier <sv...@meiers.net>.
Hi,
FileUploadField works with IModel<FileUpload> only.
Usually you keep the fileUpload in your component and explicitly do
something with its bytes in your #onSubmit().
Hope this helps
Sven
On 09/21/2014 01:58 AM, Hasan Çelik wrote:
> hi,
>
> i have a file upload process for image.
>
> fileupload.java
> https://gist.github.com/cortix/9079660
>
> User1.java
> https://gist.github.com/cortix/f5fbc0a137d6acfa9b40
>
> fileupload.html
> https://gist.github.com/cortix/9082148
>
> i got this error
> https://gist.github.com/cortix/9079743
>
> ...
> final FileUploadField fileUpload = new FileUploadField("fileUpload",new
> PropertyModel(user1, "photo"));
> form.add(fileUpload);
> ...
>
> i think i should change my ProperyModel or the method for images to save
> database because in my pojo class my object type is byte[]... When i use
> this way, i get error... i am thinking if this PropertyModel change, i can
> fix this problem but i don't know how can i use this PropertyModel for byte
> type..
>
>
> Web Site : www.berkadem.com
> E-mail: hasancelik@berkadem.com
> Phone: +90 312 473 38 86
> Mobile Phone: +90 544 640 96 25
> Address : Öveçler 4. Cadde 1325.sokak No:5/1 Çankaya ANKARA
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org