简体   繁体   中英

How do I reset inputFile control in ADF form?

My ADF form is working fine except for a weird caching problem. I have an ADF form that does not use a database. It has an input file field whereby a user can choose a spreadsheet. When they click the Process File button it reads the spreadsheet, does some data manipulations and writes a fixed file. When they hit the Process File button, the text box that contained the file name turns into basically a label with no box showing and it shows the name of the file they uploaded. When I close the browser and reopen it, the page comes back up with that last file chosen still showing in the label. I also notice that the value of a global variable (within the class) which is initialized to zero at the beginning of the program started with the last value it had at the end of the first test. Refreshing the page numerous times in the browser did nothing to reset the page. Why is it behaving this way? I would think if the browser is closed when the page is brought up again it should be starting fresh. I got around the global variable thing by setting to zero again further along in the program, but I could not set the file name value to null. It seems it wouldn't take effect until a button was clicked. Is there some kind of refresh I should be doing? I tried a whole page refresh with Java, but that didn't seem to work.

I should also mention I was using the Internet Explorer browser and when I tried it in a different browser where I hadn't brought up the page before, Chrome, it still had the file already chosen. The only time it seems to start fresh is when I re-deploy the application.

I am using jDeveloper 11.1.1.4. (Tried it using 11.1.1.6 as well) Weblogic server is 10.3.6. I can tell you that I checked the session tab in the weblogic-application.xml file. And the only thing checked is the Enable SessionTracking and Enable URL Rewriting for Session Tracking. In Memory Session is Unlimited. Under Cookies, Enable cookies and Enable HTTP proxy caching of cookies is checked. Under Cookie lifespan, Cookies never expire is selected. Though, I'm not setting any cookies, unless this is doing something behind the scenes. Persistent Store is set to Memory.

Everything else is blank. I tried unchecking Enable Session Tracking and the Enable URL Rewriting and re-deploying but the page just hung and wouldn't load at all.

So, that's where I'm at. I've been trying to find a way maybe to reset the inputFile object but thus far am having no luck. I am a newbie to ADF and Java, so please make any suggestions with that in mind, I may need a little more detail. Thanks.

Assuming you did not explicitly bind the value property of the inputFile component to a managed bean property, you simply need to call resetValue() on the component instance.

  1. Create a managed bean in request or backingBeanScope
  2. Use the af:inputFile component "binding" property to create a reference to this bean (JSF component reference)
  3. Have a command button or event you listen for to access the component reference and call resetValue() on it

The above makes it work. Now, lets polish it up:

Among JSF developers, the use of backing beans and component bindings is not considered recommended and dynamic component lookup is preferred instead. So you can skip step 3 and simply use FacesContext.getCurrentInstance().getViewRoot().findComponent('id_of_inputFileComp'); to get a handle to the RichInputFile instance . The tricky thing with this approach is that you need to be aware of naming containers.

Frank

you can use the following line in the valueChageListener (ValueChangeEvent vce) of the inputFile:

oracle.adf.view.rich.util.ResetUtils
ResetUtils.reset(vce.getComponent())

Jdeveloper version 12.1.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM