How to properly upload files - primefaces

I have a problem with file upload. I have a page, where there is an output box. And if I need to make more then 1 mP (myProduct for example) and I add the same section all look OK. But when I fill first mP and add next, the file uploaded in first section in not OK. If I choose file in first section, and click to upload, get error "The file was not choosed"....Some tips how to solve it? btw: sorry for my english
<div class="ShadowBox whiteback RedBorderedBox ui-fluid">
<div class="CI">
<p:outputPanel styleClass="C100">
<h1 class="BT">#{msg.mP}</h1>
<div class="C100">
<p:dataList id="#{id}_mPList"
value="#{mPs}" var="rec"
type="definition" emptyMessage="No data">
<p:panelGrid columns="8" layout="grid"
style="border:0px !important; background:none;"
styleClass="ui-panelgrid-blank"
columnClasses="ui-grid-col-5, ui-grid-col-5">
<p:inputTextarea placeholder="#{msg.mPPro}"
value="#{rec.p}" disabled="#{MyBean.locked}"
rows="1">
<p:ajax listener="#{MyBean.inv()}" update="#(.buttonPanelClass)"
event="change"/>
</p:inputTextarea>
<p:fileUpload value="#{MyBean.modFile}" mode="simple" skinSimple="true" label="Choose file"
update="#{id}_mPList #(.buttonPanelClass)" />
<p:commandButton value="Upload" action="#{MyBean.saveModFile(rec, modCat)}" ajax="false"
update="#{id}_mPList #(.buttonPanelClass)" icon="fa fa-arrow-up green"/>
</p:panelGrid>
<f:facet name="footer">
<p:commandButton immediate="true"
update="#{id}_mPList #(.buttonPanelClass)"
action="#{MyBean.addMedProduct(medProducts)}"
value="#{msg.add}"
disabled="#{MyBean.locked}"/>
</f:facet>
</p:dataList>
</div>
</p:outputPanel>
</div>
</div>
</p:outputPanel>

Related

fileupload progress Bar misplacing primefaces

In the above picture, while uploading second file, it is showing progress bar for first fileupload
<h:panelGroup>
<h:outputText id="keyupload" value="Key file(extension should be .key)"/>
<p:fileUpload id="keyfileUpload" label="Upload KeyFile" fileUploadListener="#{exampleBean.keyFileUpload}" mode="advanced" auto="true" allowTypes="/(\.|\/)(crt|key)$/" />
</h:panelGroup>
<p:separator id="separator1"/>
<h:panelGroup>
<h:outputText id="certupload" value="Certificate and Key file(extension should be .crt)"/>
<p:fileUpload id="crtUpload" label="Upload File" fileUploadListener="#{exampleBean.crtFileUpload}" mode="advanced" auto="true" allowTypes="/(\.|\/)(crt|key)$/" />
</h:panelGroup>
How to keep proper way, can anyone please help

f:setPropertyActionListener not setting the property in p:datatable

SOLUTION
Long story short, "not empty #{pastTxModel.currentTx.xml}" should be "#{not empty pastTxModel.currentTx.xml}". Yeah, I know...
UPDATE
The problem is here:
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="not empty #{pastTxModel.currentTx.xml}"></p:inputTextarea>
Long story but the solution is -
Part 1-
<h:form id="alltxform">
<p:dataTable id="tablealltx" var="transaction" value="#{transactionListModel.txList}">
<p:column>
<p:commandButton update=":alltxform:xmlDetail" action="#{transactionListModel.setSelectedTx(transaction)}">
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Detail" widgetVar="dialog">
<p:outputPanel id="xmlDetail">
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="not empty #{pastTxModel.currentTx.xml}"></p:inputTextarea>
</p:outputPanel>
</p:dialog>
</h:form>
Then Change -
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="not empty #{pastTxModel.currentTx.xml}"></p:inputTextarea>
To -
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="#{not empty pastTxModel.currentTx.xml}"></p:inputTextarea>
You need to update the whole dialog after clicking on the button.
<p:commandButton update=":alltxform:Detail" oncomplete="PF('dialog').show()">
<f:setPropertyActionListener value="#{transaction}"
target="#{transactionListModel.selectedTx}" />
</p:commandButton>

trigger blockui from link within datagrid

I have the below datagrid which displays a list of student names as link.
<h:form id="gsform">
<p:dataGrid var="stuvar" rendered="#{gradeSheetController.listStudent != null}"
value="#{gradeSheetController.listStudent}" columns="5" layout="grid">
<p:commandLink actionListener="#{gradeSheetController.readStudentGradeSheet}"
update=":gsform:gscont, :gsform:buttoncont">
<h:outputText id="stname" style="font-size:16px" value="#{stuvar.studentFirstName}" />
<f:param name="selstudent" value="#{stuvar.studentSeq}" />
</p:commandLink>
</p:dataGrid>
I also have the below blockUI to freeze the screen until backend processing is done, currently used for a Save button.
<p:blockUI block=":entirePageBody" trigger="savebutton">
<h:panelGrid id="blockContent" columns="2">
<h:graphicImage library="images" name="loading.gif" style="margin-right:12px; vertical-align:middle;" />
<h:outputText value="Please wait, data is being processed..." style="white-space:nowrap;" />
</h:panelGrid>
</p:blockUI>
Now, I would also like to trigger the blockUI when the Student name link is clicked. Obviously, since the number of students will be dynamic and being within the datagrid, the code generated includes other aspects to the id like id="gsform:j_idt168:1:stname", id="gsform:j_idt168:2:stname" and so on.
Have no clue how to trigger the blockUI on click of the Student name link within the datagrid, please suggest.
Triggering/Hiding the blockUI from within dataGrid using onclick/oncomplete
<p:dataGrid var="stuvar" rendered="#{gsExamController.listStudent != null}"
value="#{gsExamController.listStudent}" columns="5" layout="grid">
<p:commandLink actionListener="#{gsExamController.readStudentGradeSheet}"
onclick="PF('bui').show()"
oncomplete="PF('bui').hide()"
update=":gsform:gscont, :gsform:remarkcont, :gsform:buttoncont">
<h:outputText style="font-size:16px" value="#{stuvar.studentFirstName}" />
<f:param name="selstudent" value="#{stuvar.studentSeq}" />
</p:commandLink>
</p:dataGrid>
<p:blockUI block=":entirePageBody" trigger="savebutton" widgetVar="bui">
<h:panelGrid id="blockContent" columns="2">
<h:graphicImage library="images" name="loading.gif" style="margin-right:12px; vertical-align:middle;" />
<h:outputText value="Please wait, data is being processed..." style="white-space:nowrap;" />
</h:panelGrid>
</p:blockUI>
A simple solution to your problem is to use Primefaces' selectors.
For example:
<p:commandLink value="Click me." styleClass="blockMeWhenClicked" />
<p:blockUI block=":ElementToBeBlocked" trigger="#(.blockMeWhenClicked)" />

PrimeFaces CommandButton is not working in Dialog

I need your help in solving the issue with the CommandButton in the dialog as I am calling a method called UpdatePrint() in the action and it is not called. The jsf page code is as follow:
<h:form id="Requests">
.
.
.
<p:commandButton update=":Requests:#{hr.dialogueName}" oncomplete="PF('#{hr.certificateDialogue}').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
.
.
<p:dialog header="cert1" widgetVar="cert1" modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:outputPanel id="HRCEEN" style="text-align:center;">
</p:outputPanel>
<p:commandButton value="Print" action="#{hrd.UpdatePrint}" type="button" icon="ui-icon-print" style="display:block;margin-bottom: 20px">
<p:printer target="HRCEEN"/>
</p:commandButton>
</p:dialog>
.
.
<p:dialog header="cert2" widgetVar="cert2" modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:outputPanel id="HRSSEN" style="text-align:center;">
</p:outputPanel>
<p:commandButton value="Print" action="#{hrd.UpdatePrint}" type="button" icon="ui-icon-print" style="display:block;margin-bottom: 20px">
<p:printer target="HRSSEN"/>
</p:commandButton>
</p:dialog>
</h:form>
I tried different ways, but I wasn't successful with them as it showed me that the section in the update is not found when I am referring in the update.
<p:commandButton update=":Requests:#{hr.dialogueName}" oncomplete="PF('#{hr.certificateDialogue}').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
The action method is not called because of the type="button" attribute - there is no submit to the server. Remove type, then the action will be triggered (the button will assume the default submit type).

disable jsf tag

I need help disabling this link click without using javascript. So this is a on jsf page where the beans would set a variable to false then the cancel should not be pressable.
<p:column style="width:14%; text-align: center;">
<f:facet name="header">
<b><h:outputText value="Action" /> </b>
</f:facet>
<a href="cancel.xhtml?id=#{requestClass.requestID}">
<h:outputText value="Cancel" />
</a>
</p:column>
Thanks in advance!
Update:
<p:column style="width:14%; text-align: center;">
<f:facet name="header">
<b><h:outputText value="Action" /> </b>
</f:facet>
<h:link disabled="#{requestBean.cancelledStatus}"
outcome="cancel.xhtml?id=#{requestClass.requestID}" value="Cancel">
<f:param name="id" value="#{requestClass.requestID}" />
</h:link>
</p:column>
that didn't actually disable the button when page is loaded even though status of request is cancelled
Update 2:
this error showing when updated to following:
<h:commandButton value="Cancel" action="cancel.xhtml?id=#{requestClass.requestID}"
disabled="#{requestBean.cancelledStatus}">
<f:param name="id" value="#{requestClass.requestID}" />
</h:commandButton>
it says:
/pending.xhtml #86,150 action="cancel.xhtml?id=#{requestClass.requestID}" Not a Valid
Method Expression: cancel.xhtml?id=#{requestClass.requestID}
Instead of using normal HTML tag <a>, you should use JSF's <h:link>. This tag has the attribute disable that can be used to disable the link. In you case, it should look like this:
<h:link disable="#{requestClass.disableCancelLink}" outcome="cancel" value="Cancel">
<f:param name="id" value="#{requestClass.requestID}" />
</h:link>