jsf 2 - How to get parametrs to BackingBean from jsf page in <ui:repeat> -
my xhtml:
<ui:repeat value="#{c.voices}" var="v"> <h:form enctype="multipart/form-data"> <p:fileupload fileuploadlistener="#{addnote.handlefileupload}" convertermessage="convertermessage" mode="advanced" update="messages" sizelimit="100000" allowtypes="/(\.|\/)(gif|jpe?g|png)$/"> </p:fileupload> <p:growl id="messages" showdetail="true"/> </h:form> </ui:repeat>
my backingbean:
public void handlefileupload(fileuploadevent event) { //int v.id= here need know v.id value ui:repeater facesmessage msg = new facesmessage("succesful", event.getfile().getfilename() + " uploaded."); facescontext.getcurrentinstance().addmessage(null, msg); }
c.voices list of object. every object have attribute id. need know id parametr in handelfileupload how can that?
sry english , ignorance of jsf primefaces beginner in both discipline.
i put v.id
in hidden field :
your xhtml:
<ui:repeat value="#{c.voices}" var="v"> <h:form enctype="multipart/form-data"> <input type="hidden" name="vid" value="#{v.id}" /> <p:fileupload fileuploadlistener="#{addnote.handlefileupload}" convertermessage="convertermessage" mode="advanced" update="messages" sizelimit="100000" allowtypes="/(\.|\/)(gif|jpe?g|png)$/"> </p:fileupload> <p:growl id="messages" showdetail="true"/> </h:form> </ui:repeat>
and in bean using facescontext
:
your backingbean:
public void handlefileupload(fileuploadevent event) { httpservletrequest request = (httpservletrequest) facescontext.getcurrentinstance().getexternalcontext().getrequest(); request.getparameter("vid"); // <= here are! }
update
as stated in comments each iteration have it's own <h:form
it's own <input type="hidden" name="vid"
. when file uploaded handlefileupload
fired data of enclosing form, vid
parameter sent correct #{v.id}
update 2
as balusc commented should preferably vid
parameter way :
public void handlefileupload(fileuploadevent event) { facescontext.getcurrentinstance().getexternalcontext() .getrequestparametermap().get("vid") // <= here are! }
Comments
Post a Comment