jsf 2 - p:dataTable and p:commandLink not working -
i have following:
<p:datatable id="photopreview" var="file" value="#{ fileuploadmb.fileslist }"> <p:column> <p:commandlink ajax="false"> <p:graphicimage value="#{ fileuploadmb.streamedcontentfromfile }" rendered="#{ file.fileisimage }"> <f:param name="n" value="#{ file.n() }" /> <f:param name="size" value="thumbnail" /> </p:graphicimage> <p:filedownload value="#{ fileuploadmb.streamedcontentfromfile }"/> <f:param name="n" value="#{ file.n() }" /> </p:commandlink> </p:column> <p:column> <p:commandlink value="remove" disabled="#{ loginmb.customerrole , !orderdetailmb.filemodificationpermitted }" action="#{ fileuploadmb.removeuploadedfile }" rendered="#{ file.uploadedfilepresent }" update="photopreview"> <f:param name="n" value="#{ file.n() }" /> </p:commandlink> </p:column> </p:datatable>
but when click on remove link, datatable not updated. know fileuploadmb.removeuploadedfile() being called. know file.isfileisimage() being called after it. nothing changes in browser. firebug's net tab shows me response contains nothing useful, not might reliable; firebug has tendency refetch urls when @ response sub-tab.
relevant code fileuploadmb :
@managedbean @sessionscoped public class fileuploadmb implements serializable { private static final logger logger = loggerfactory.getlogger(thread.currentthread().getstacktrace()[1].getclassname()); private map<integer, ordercustomerfile> uploadedfileslist; private list<ordercustomerfile> uploadedfilestodelete; private static final int max_number_of_files = 5; private list<filen> fileslist; // ---------------------------------------------------- public boolean fileisimage(int rowindex) { if( rowindex == 0 ) { logger.debug( "rowindex={}", rowindex ); logger.debug( "uploadedfilelist={}", uploadedfileslist ); logger.debug( "uploadedfilelist.keys={}", uploadedfileslist.keyset() ); } if( !uploadedfileslist.containskey(rowindex) ) { if( rowindex == 0 ) logger.debug( "nope" ); return false; } string ct = uploadedfileslist.get(rowindex).getcontenttype(); if (ct.contains("gif") || ct.contains("jpeg") || ct.contains("png") || ct.contains("jpe")) return true; else return false; } // ---------------------------------------------------- public void removeuploadedfile() { facescontext context = facescontext.getcurrentinstance(); logger.debug( "context={}", context ); string n = context.getexternalcontext().getrequestparametermap().get("n"); logger.debug( "n={}", n ); removeuploadedfile( integer.valueof( n ) ); } // ---------------------------------------------------- public void removeuploadedfile(int rowindex) { logger.debug( "uploadedfilelist={}", uploadedfileslist ); logger.debug( "uploadedfilelist.keys={}", uploadedfileslist.keyset() ); logger.debug( "rowindex={}", rowindex ); if( uploadedfileslist.get(rowindex).getuploadedfile() == null ) { logger.debug( "wants delete {}", uploadedfileslist.get(rowindex).getfilepath() ); uploadedfilestodelete.add( uploadedfileslist.get(rowindex) ); } uploadedfileslist.remove( rowindex ); logger.debug( "uploadedfilelist={}", uploadedfileslist ); logger.debug( "uploadedfilelist.keys={}", uploadedfileslist.keyset() ); } // ---------------------------------------------------- public list<filen> getfileslist() { if( fileslist == null ) buildfileslist(); //logger.debug( "fileslist={}", fileslist ); return fileslist; } public void buildfileslist() { map<string,object> viewmap = facescontext.getcurrentinstance().getviewroot().getviewmap(); fileslist = new arraylist<filen> (); for( int q=0; q<max_number_of_files; q++ ) { filen file = new filen (this, q); fileslist.add( file ); logger.debug( "file={} hashcode={}", file, file.hashcode() ); viewmap.put( string.valueof( file.hashcode() ), file ); } } // ---------------------------------------------------- public streamedcontent getstreamedcontentfromfile() { // see http://stackoverflow.com/questions/8207325/display-image-from-database-with-pgraphicimage/12452144#12452144 facescontext context = facescontext.getcurrentinstance(); if (context.getcurrentphaseid() == phaseid.render_response) { logger.debug( "render_response phase" ); // so, we're rendering html. return stub streamedcontent generate right url. return new defaultstreamedcontent(); } string n = context.getexternalcontext().getrequestparametermap().get("n"); string size = context.getexternalcontext().getrequestparametermap().get("size"); logger.debug( "n={}, size={}", n, size ); return streamedcontentfromfile( integer.valueof( n ), size ); } // ---------------------------------------------------- public streamedcontent streamedcontentfromfile( int rowindex ) { return streamedcontentfromfile( rowindex, "normal" ); } // ---------------------------------------------------- public streamedcontent streamedcontentfromfile( int rowindex, string size ) { logger.debug( "rowindex={}", rowindex ); //fichier provenant de la bd (ayant deja ete sauvegarde) if (uploadedfileslist.get(rowindex).getfilepath() != null) { ordercustomerfile iof = uploadedfileslist.get( rowindex ); try { java.io.file file = new java.io.file( iof.getfilepath() ); if (file.exists()) { logger.debug( "streaming file {} ct={}", iof.getfilepath(), iof.getcontenttype() ); bufferedinputstream bif = new bufferedinputstream( new fileinputstream( new java.io.file(iof.getfilepath()))); logger.debug( "bif={}", bif ); string name = iof.getfilenameoriginal(); if( name == null ) name = iof.getfilepath().substring(iof.getfilepath().lastindexof("/")+1); logger.debug( "name={}", name ); return new defaultstreamedcontent(bif, iof.getcontenttype(), name ); } } catch (filenotfoundexception e ) { logger.error( null, e ); messagesmb.showerrormessage(messagesmb.order_details_file_not_found); } //fichier n'ayant pas encore ete sauvegarde dans la bd } else if (null != uploadedfileslist.get(rowindex).getuploadedfile()) { try { ordercustomerfile file = uploadedfileslist.get(rowindex); return new defaultstreamedcontent( file.getuploadedfile().getinputstream(), file.getcontenttype(), file.getfilenameoriginal() ); } catch (ioexception e ) { logger.error( null, e ); messagesmb.showerrormessage(messagesmb.error_general); } } return null; } // ---------------------------------------------------- public boolean uploadedfilepresent(int rowindex) { return uploadedfileslist.containskey(rowindex); // && !hasbeenpersisted( rowindex ); } }
relevant parts of filen:
@managedbean @viewscoped public class filen implements serializable { private static final logger logger = loggerfactory.getlogger(thread.currentthread().getstacktrace()[1].getclassname()); private integer n; private fileuploadmb fileuploadmb; // ---------------------------------------------------- /** creates new instance of file */ public filen( fileuploadmb fileuploadmb, integer n ) { this.n = n; this.fileuploadmb = fileuploadmb; logger.debug( "n={}", n ); } // ---------------------------------------------------- public int n () { return n.intvalue(); } // ---------------------------------------------------- public string getn () { return n.tostring(); } // ---------------------------------------------------- public boolean isfileisimage () { if( n.equals( 0 ) ) logger.debug( "n={}", n ); return fileuploadmb.fileisimage( n.intvalue() ); } // ---------------------------------------------------- public boolean isuploadedfilepresent () { return fileuploadmb.uploadedfilepresent( n ); } }
(and yes, have lot of other problems, filen not being view-scoped bean.)
using jsf-2.1, primefaces-3.0, glassfish-3.1.2.2, jdk-1.7.0
firebug net response is:
<?xml version='1.0' encoding='utf-8'?> <partial-response><changes><update id="j_idt86"><![cdata[<div id="j_idt86" class="ui-messages ui-widget"></div>]]></update><update id="javax.faces.viewstate"><![cdata[3615293429385705722:7636138965730106845]]></update></changes></partial-response>
httpfox gives me same thing:
<partial-response> <changes> <update id="j_idt86"> <div id="j_idt86" class="ui-messages ui-widget"></div> </update> <update id="javax.faces.viewstate">-2752869461800547313:-2875920138022122822</update> </changes> </partial-response>
this on https, getting tcpdump harder.
using primefaces-3.0
the <p:datatable>
has in older pf 3.x versions bug caused <p:datatable>
can't ajax-updated command originated inside <p:datatable>
itself.
you have 2 options:
upgrade at least primefaces 3.4.
ajax-update parent component instead. perhaps
@form
?
the alternative option turn off ajax ajax="false"
.
Comments
Post a Comment