Which JSF-tag to use to get the path of an Input Directory on the client side? - jsf

Is there an input directory for JSF, or library like Omnifaces or Primefaces? I don't need <h:inputFile> as the file actually no need to be uploaded, I would like to provide a field for user to input the path of a file for example:
C:\Folder One\myFile.txt
and ManagedBean will interpret the path, for example, read the content of the file. I don't want user to enter the file path manually in input text. And I don't have the client/server issue as the user will select the file on the machine which my JSF application is deployed.
If such component is not available, is there any workaround? like maybe I can provide a <h:inputFile> and get path from it?

Related

Threepenny-gui: get file path via 'file' input

I am going to write simple frontend for my console tool. Generally, it takes a few parameters and input file path for further opening and processing.
My idea was to place something like
UI.input # set (attr "type") "file" # set UI.text "input filename"
And then get the selected file path via 'value'.
But it appears that due to security reasons browsers do not provide full path to selected file.
Is it possible to place any file chooser with threepenny-gui?
As far as I know, web browsers do not allow you to obtain a filepath via the fields, for reasons of security. You can only obtain the file contents. Of course, you can always ask for a filepath in a plaintext input field, but that is certainly less convenient for the user.
Filepaths can be obtained from a file chooser dialog if you combine Threepenny with the Electron framework. Working with files is one of the reasons for using Electron.

JSF external file based on locale

I have an JSF application where I want to send an email from. Now I don't want to put the email's content in my i18n file. I thought to save it in an external file, lets say email1_de.txt and email1_en.txt.
Can I somehow load this file depending on the user's locale?
Thanks
Why don't you just use a resource bundle.
1. Create a Message.properties file in one of your source code packages and then in that file, add your email content, in plain or HTML format as follows:
message.test3 = This is "<h2>message.test4</h2>"
message.param1 = This is "message.param1" - {0}
message.param2 = This is "message.param2" - {0} and {1}
You may even include parameters.
Declare your resource bundle in your faces-config.xml file
You can call the text in your resource bundle from you class or from your HTML files.
You may look at this example: http://www.mkyong.com/jsf2/jsf-2-0-and-resource-bundles-example/
If you are dealing with different locales, then you can look here: http://www.mkyong.com/jsf2/jsf-2-internationalization-example/
It is explained pretty well.

Where can I find (Path in the bundle) the User create/edit screen source?

I am just trying to find the front end source code for user creation and edit pages. But I tried search by different label text and ID's but no use. Can anyone please tell me the path for user add and edit page source files.
As you can see, the URL is something like:
http://localhost:8080/group/control_panel/manage?p_p_id=125&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&refererPlid=15595&_125_redirect=%2Fgroup%2Fcontrol_panel%3FrefererPlid%3D15595&_125_struts_action=%2Fusers_admin%2Fedit_user
Searching in struts configurations you can see that struts_action=/users_admin/edit_user should refer to jsp file edit_user.jsp
That file is located in users_admin... so the path you are seeking should be html/portlet/users_admin inside portal-web project.
This is on GitHub.

Get file path of uploaded file from p:fileUpload

I would like to upload one file at a time, get the path of each file and add it to a list. It would later be used to save them all in a permanent directory like E:/myfile/....
I tried the following PrimeFaces component:
<p:fileUpload value="#{fileUploadView.file}" mode="simple" />
However, I am unable to get the file path. How can I get it?
The enduser won't send you the full client side file path. Even then, if it did, how would you ever get the file contents by only the path? If it were possible, it would have been a huge security breach as basically anyone on the world would be able to unaskingly scrape files from anyone else's disk through the entire Internet.
Usually, only the filename is being sent and you should even not use exactly that filename to save the obtained content on disk in order to avoid files being overwritten in case (another) enduser coincidentally uploads a file with exactly same name. You should use it at most as metadata (e.g. to prefill the Save As filename in case enduser want to download it back at a later moment).
You should actually be interested in the actual file content sent to you in flavor of InputStream or byte[], not the original client side path nor filename. The file content is sent only once and you should immediately read and write it to a more permanent location in the server side once the bean action method hits. Then, keep track of the (autogenerated/predefined!) filenames/paths of those saved files in some List<String> or List<File> in the view or perhaps the session scope.
See also:
How to save uploaded file in JSF

J2ME: how to define path for fileConnection

About writing on the text file, i have a problem to define the path. I m developping with NetBean and I put my txt file in the "nbproject" folder. I can read it by using "this.getClass().getResourceAsStream(fileName)". But for writing i don't know how to define the path.
When you put the file in project folder, it is packaged in the jar file. The jar file is read-only. So your Midlet can not write into it. For security reasons. This is good.
If you need to write data, you can either use RecordStore or FileConnection.
RecordStore is portable. It does not ask for permissions. So for simple things, like settings for your midlet, this is the best option.
You can just define your whole file content as one Record.
For FileConnection, your midlet need to ask for permissions. But you have real files for example on SD-Card, there is no other way.

Resources