Problem with seam's file upload
maxseam Dec 12, 2008 10:48 AMHello!
I have a page, where I want to give the user the possiblity to upload an avatar. I make this in a richfaces ModalPanel. I include a seam fileUpload component and two buttons (cancel and save).
My problem is, if I choose an image and click on the save button my action always gets as data and contentType null.
Here is my code:
xhtml-file (ModalPanel):
<rich:modalPanel id="uploadPanel" height="100" width="320"> <f:facet name="header">Fotoupload</f:facet> <f:facet name="controls"> <h:panelGroup> <h:graphicImage value="/img/close.png" style="cursor:pointer" id="closeLink"/> <rich:componentControl for="uploadPanel" attachTo="closeLink" operation="hide" event="onclick"/> </h:panelGroup> </f:facet> <h:form> <s:fileUpload accept="image/png, image/gif, impage/jpeg" data="#{tfotoHome.instance.timage}" contentType="#{tfotoHome.instance.tcontenttype}" /> <h:panelGrid columns="2"> <s:button value="Abbrechen"/> <h:commandButton type="submit" value="Speichern" action="#{tfotoHome.addAvatar(tuser)}"/> </h:panelGrid> </h:form> </rich:modalPanel>
This is the code of my TfotoHome:
@Name("tfotoHome") public class TfotoHome extends EntityHome<Tfoto> { @Logger Log log; public void setTfotoTfotoId(Integer id) { setId(id); } public Integer getTfotoTfotoId() { return (Integer) getId(); } @Override protected Tfoto createInstance() { Tfoto tfoto = new Tfoto(); return tfoto; } public void wire() { getInstance(); } public boolean isWired() { return true; } public Tfoto getDefinedInstance() { return isIdDefined() ? getInstance() : null; } public String addAvatar(Tuser tuser) { Tfoto foto = this.getInstance(); String persist = ""; if(foto==null) log.info("foto is null"); log.info(foto.getTcontentType()); foto.setTdescription("avatar"); foto.setTuser(tuser.getTuserId()); this.setInstance(foto); log.info(persist = this.persist()); return persist; } }
As you can see I am calling the addAvatar method as action in my ModalPanel. When I am in my addAvatar method, my FotoInstance is not null, but it's content is (tcontentType and timage).
I don't know why these values are null. Maybe because they are not set by the seam uploadFile component? Maybe there is some problem with the submit (so that the values are not set)?
I tried many different things, but nothing worked (setting @In values, setting scopetype to session, ...).
It would be great if someone of you knows what my mistake is! If you need more code, please let me know.
Thanks!
regards,
max.