File upload implementation using RichFaces 4.3.7 - jsf

I am trying to add a file upload component in my application, I used Tomahawk, but it doesn't work with ajax which is essential in my case. So I used RichFaces, I add these jars to my lib folder :
richfaces-core-api-4.3.7.Final.jar
richfaces-core-impl-4.3.7.Final.jar
richfaces-components-api-4.3.7.Final.jar
richfaces-components-ui-4.3.7.Final.jar
then I added this tag to my index.xhtml
<rich:fileUpload fileUploadListener="#{createListBean.listner}"
maxFilesQuantity="1" id="file" immediateUpload="false"
acceptedTypes=".xls,.xlsx,.csv" allowFlash="false">
<a4j:ajax event="uploadcomplete" render=":contact-form:error_mess :contact form:records-form-table" />
</rich:fileUpload>
So my problem is there is an iframe appeared and also I can't find the upload button , and the css looks awful , all I need is an upload file input text and a button to upload with my own css on it. Thanks in advance

I dont know whether the component using iframe or new XMLHttpRequest extension FormData object to implement ajax functionality. But when you add component to your page, it will show a component like in this page Richfaces Showcase. At first upload button is not visible, but when you select some files to upload, it will be visible automatically.

Try considering Primefaces Like this as it is Ajax enabled and very stable except IE 7. you can find many different file uploader like basic, multi, drag n drop, file filter, size limit

Related

Is loading triggered from the click of a submit button generated by h:commandButton a full load?

A jsf page contains a form with a commandButton element like <h:commandButton action="#{bean.search}". This submit button will trigger a bean, which then will send more data back to this same jsf page.
Question: after the submit, is the jsf page fully loaded again? or is just the part containing the newly retrieved data reload and other parts are not loaded again?
By default JSF will fully reload the page. This can be tested by looking at the browser network developer tools while submitting the commandButton. If you intend to only render a part of the page - e.g. a label that outputs the result - you can do that by using AJAX.
For example if your commandButton is in a form, by adding
<f:ajax execute="#form" render="#form:result" />
within your commandButton tag, you can specify that only the contents of the form are processed by the server and only the label with the ID 'result' is rendered.
For further information take a look at this guide for AJAX in JSF: https://www.beyondjava.net/a-comprehensive-guide-to-jsf-ajax
You will see that the author shows the full page loading without AJAX.
Alternatively here is the official documentation for <f:ajax>:
https://jakarta.ee/specifications/faces/2.3/vdldoc/f/ajax.html

Is it possible to show only the confirm, and not the cancel button icon in Prime Faces DataTable rowEditor?

Is it possible to show only the confirm, and not the cancel button icon in Prime Faces DataTable rowEditor?
I ended myself with this approach
As stated by #Kukeltje it's possible to manage similar problems on client using
some css to hide it (it is all html, css and javascript on the client).
I choose jquery to handle html, css, and javascript (I'm relatively new to jsf/primefaces but I read it's based on jquery).
So in managed bean I was able launch scripts like this:
PrimeFaces.current().executeScript("$('#myForm\\\\:myContainer .ui-row-editor-close').eq(-1).remove();");
or even in XHTML/JS script like this:
<h:outputScript library="js" name="myScripts.js" />
$(document).ready(function() {
$("#myForm\\:myContainer .ui-row-editor-close").last().remove();
});
Anyway with this approach you need to be carefull, any ajax call which update part of the page involved reset to default, so cancel button will re-appear.

h:command button oncomplete action

When downloading file from server if i use a4j:commandLink file download fail(mean file written to browser screen) if i use h:commandLink it is okay.I want to show a rich modal panel when file downloading but standard components not have a on complete action so i cant hide modal panel after file downloaded .How can i workaround this issue,I am using rich faces 3.3
<h:commandLink value="Download"
action="#{logSearcher.downloadFile}"
onclick="Richfaces.showModalPanel('ajaxLoadingModalBox',{width:450, top:200})"
immediate="true" >
<f:setPropertyActionListener value="#{log}"
target="#logSearcher.selectedLogLine}"
/>
</h:commandLink>
You can use de rich:componentControl or the JS API show function (#{rich:component('mp')}.show).
http://livedemo.exadel.com/richfaces-demo/richfaces/modalPanel.jsf?s=blueSky#
The <a4j:commandLink> sends by default an asynchronous (ajax) request. You cannot download files using asynchronous requests. JavaScript simply does not offer facilities to turn a XMLHttpRequest response into a Save As dialog. You need to download files using a normal synchronous request. The <h:commandLink> does that.
Your best bet is to use the onclick attribute of <h:commandLink> to close the modal panel. If necessary with a setTimeout().

How to Refresh only components in certain 'box'

Say I have a websites with 3 panel grid (just for example..) and I would like to have buttons inside each grid that only cause the contents of that grid to refresh so the rest of the page doesn't necessarily have to refresh.
How do I do that?
I tried to have a form sorround that grid but it seems like the rest of the page still gets refreshed.
A Note - I'm trying to achieve something like what happens when you work with a picklist. when you move the objects between the lists there doesn't seem to be any page refresh...
Thanks!
If you are using RichFaces, you should definitivly check the Ajax chapter of the RichFaces manual. I think you will find everything you need to know there.
Here a small example for partial page rendering:
<a4j:commandButton value="update" reRender="infoBlock"/>
<h:panelGrid id="infoBlock">
<!-- Some content-->
</h:panelGrid>

richfaces how to detect mouse events

sorry if the answer to this is obvious but I couldn't find it.
How do I detect if the user has clicked, dragged etc. on an image (or other element)?
Thanks in advance!
There are several way of doing this:
In HTML it would be something like:
<img src="images/myImage.jpg" onclick="someJSFunc()"/>
In the case of Richfaces you'd probably want to invoke some sort of server side logic through an Ajax request after your image has been clicked, so, the most appropriate thing would be:
<img src="images/myImage.jpg">
<a4j:support event="onclick" action="#{myBean.someActionMethod}" reRender="someComponent"/>
</img>
For more information of how to add Ajax behavior to standard HTML components tags with Richfaces see the a4j:support component description.

Resources