Using File Download Control with Java Bean in XPages -
i use standard xpages xp:filedownload control , bind java bean rather document source.
i have rtf field in form - 'resourceattachments' - along several other fields in in storing several attachments , nothing else.
can provide me example or point me documentation. have similar requirement xp:uploadcontrol, can find samples create new document, struggling implement adding , saving existing documents, guess should post question though, 2 go thought @ least mention here.
many thanks.
mark
public class trainingmodule implements serializable { private static final long serialversionuid = -6998234266563204541l; private string description; private ???? resourceattachments; --something here ?? private string unid; public trainingmodule() { string documentid = extlibutil.readparameter(facescontext.getcurrentinstance(), "key"); if (stringutil.isnotempty(documentid)) { load(documentid); } } public string getunid() {return unid;} public void setunid(final string unid) {this.unid = unid;} public string getdescription() {return description;} public void setdescription(final string description) {this.description = description;} ? attachment getter & setter here?? public void load(final string unid) {setunid(unid);{ document doc = null; try { doc = extlibutil.getcurrentdatabase().getdocumentbyunid(getunid()); setdescription(doc.getitemvaluestring("description")); ??some load here here?? } catch (throwable t) { t.printstacktrace(); } { try { doc.recycle(); ?some other recycle here? } catch (exception ) { // fail silent } }
in custom control amongst other things have...
<xp:this.beforepageload><![cdata[#{javascript:if(param.containskey("key")) {viewscope.put("docattach",(param.get("key")));}}]]></xp:this.beforepageload> ....... <xp:filedownload rows="30" id="filedownload2" displaylastmodified="false" value="#{trainingmodule.resourceattachments}" hidewhen="true" allowdelete="true"> </xp:filedownload>
i have dealt similar problem last year. haven't looked appropriate binding fileupload. instead, used different approach.
when submit xpage file upload, upload file disk (regardless of binding) , create com.ibm.xsp.http.uploadedfile
object in requestmap
. can grab bean method , magic.
this ibm connect 2014 demo , have used technique upload file basecamp.
xsp code simple (here github repo)
<xp:fileupload id="fileupload1"></xp:fileupload> <xp:button id="button1" value="upload local file"> <xp:eventhandler event="onclick" submit="true" refreshmode="complete"> <xp:this.action> <xp:executescript script="#{bcs.uploadlocalfile}"> </xp:executescript> </xp:this.action> </xp:eventhandler> </xp:button>
bcs
managed bean , here code snippet upload (from github repo)
public void uploadlocalfile() { facescontext facescontext = facescontext.getcurrentinstance(); externalcontext externalcontext = facescontext.getexternalcontext(); httpservletrequest request = (httpservletrequest) externalcontext.getrequest(); string fileuploadid = extlibutil.getclientid(facescontext, facescontext.getviewroot(), "fileupload1", false); uploadedfile uploadedfile = ((uploadedfile) request.getparametermap().get(fileuploadid)); if (uploadedfile == null) { facescontext.addmessage("messages1", new facesmessage(facesmessage.severity_error, "no file uploaded. use file upload button upload file.", "")); return; } java.io.file file = uploadedfile.getserverfile(); string contenttype=uploadedfile.getcontenttype(); string filename = uploadedfile.getclientfilename(); // removed unrelated code... }
so, basically, requestmap
. uploadedfile
object refers file object has been uploaded temporary area on server , it's mapped clientid
of fileupload
component.
after point, might create stream , attach file field. when bind field, document wrapper same thing, guess.
Comments
Post a Comment