I have a reports page that submits user generated queries for data retrieval. When no data exists for the query, I add a facesmessage-"No data" to the session and associate it with the submit button so, it shows up next to the button.
When the user modifies the query and resubmits it I want the 'no data' msg to be cleared. I couldn't find a way to do this. I couldn't find any messages in the sessionmap or requestmap, so I couldn't use removemessage().
So, for the time being I am using a hack by setting the facesmessages to blank summary and detail. How do I clear the msg for every query submitted?
Thanks.
BalusC,
Couldn't find a reply button, so I am editing the original post
Here's what I have:
JSF 1.2,
Richfaces 3.3
The backing bean for my report page is sessionscoped. The page has a dropdown menu to select report types and a submit button hooked up to an action(genrep). The button is associated with a rich:message tag.
When a report type is selected and submitted, genrep() checks the database to see if there is any data, if none exists it instantiates a facesmessage, sets summary & detail to "No data" and adds it to the submit button via the addmessage method of facescontext.
When user submits another query that has data, genrep() gets the response stream from the facescontext, sets the contentype to "application/vnd.ms-excel" and writes data to it. Closes & flushs the stream and calls responsecomplete(). Except now I still see the 'no data' message next to the button from the previous no data query.
Thanks.
When user submits another query that has data, genrep() gets the response stream from the facescontext, sets the contentype to "application/vnd.ms-excel" and writes data to it. Closes & flushs the stream and calls responsecomplete(). Except now I still see the 'no data' message next to the button from the previous no data query.
So, you're providing a file download, but you're expecting the current page to refresh as well. That's not possible due to the nature of HTTP. You cannot send two responses back on a single request (one for the file download and another one for the new page). Best what you can do is to let the client send two requests or to hide the message using a line of JavaScript in the onclick attribute. The latter is more suitable in this particular case.
Related
I am new in React.js, and I am trying to figure it out how to set up some functionality in form.
What I trying to do is the following:
1) Delete the records/inputs after clicking on the submit button (After submitting the information, the records are stored in the database, but the record/inputs are still displayed in the form.
2) After clicking the submit button, I would love to receive the following message in order to let the user know that the information was successfully submitted
This is part of my code in my component:
For value reset :
Bind a custom function to the onSubmit form method, this function will reset the form value, submit the data and display the success alert
Reset the field values using setState
Submit the data using the API system you use
Add a new boolean state to tell the page to display your alert or not.
Set the boolean state to true in your submit method
Add a display condition in the render method, displaying the alert if the boolean is set to true, and else nothing
I am using JHipster 3.3.0 and generated code using JDL.
Out of the box, each entity has its own popup dialog page for editing and saving data, i.e. {entity}-dialog.html. And after clicking the Save button, the dialog will close then the entity list page (i.e. {entity}s.html) will display the alert message 'A new <entity name> is created/updated with identifier {primary key}' to indicate outcome of save by using <jhi-alert-error></jhi-alert-error>.
Now I am implementing a one-to-many relationship for 2 entities, say User and Account(i.e. a User can have many Accounts)
such that the editing and saving of both entities happen in the same User page(i.e. User-dialog.html).
All Accounts of the User are displayed in an Account table, each row of the table will have a Save button to save data
of the Account after editing the data in the row.
This is all working fine. However, I noticed after clicking the Save button of Account row, I can see the background User list page
displaying the alert message mentioned above rather then in the current page.
I can't figure out how to display the alert message in the current page as opposed in the entity list page, which is the
default behavior.
I am missing some logic here. Any idea?
Basically, the <jhi-alert-error></jhi-alert-error> in my <entity>-dialog.html page is ignored and won't display message for outcome of successful save except for error message from Form validation.
Thanks in advance,
Sam
Ooops,silly me. Just found the answer.
The alert message 'A new is created/updated with identifier {primary key}' was displayed because the tag <jhi-alert></jhi-alert> was used, it was never
<jhi-alert-error></jhi-alert-error>.
I have an XPage that displays fields in a document. I also have the ability to pop out a new window that displays those same fields. I'm implementing a document locking scheme so that the two instances can't cause conflicts (and this is how I'm testing it).
A problem I've run into is that when the user edits the document in the pop out and saves it, a partial refresh of the panel containing those same fields in the original page doesn't show the updated data.
The save in the pop out was successful, and I can see in the Notes client that the document does indeed have the new value, but the original page simply won't show the new value. A complete page refresh using the reload button in the browser works, but I'd like to trigger this programmatically and as quickly as possible, hence the partial refresh.
Does anyone know what is going wrong? Is the NotesXspDocument in the original page getting out of sync with the backend document? I read about document1.getDocument(true), but that doesn't seem to do anything.
(As usual, I can't supply source code unfortunately....)
Once the NotesXspDocument is loaded with the XPage, a partial refresh does not update the xspDoc from the back-end DB, but from the in-memory DataSource.
You will need to refresh the XPage:
Reload the url from browser or in ssjs with a context.reloadPage()
Trigger full refresh when logged out in 8.5.3. I don't care if the data is lost, I just want to trigger full refresh if partial refresh fails in case user is logged out or session has timed out.
I have two windows open. If I press the logout button on window 2, and then come back onto window 1 and try to do a partial refresh, it returns nothing (just blank value for that control). So how can I trigger a full refresh when the user is logged out?
I tried onComplete, onStart and onError client side events, but cannot figure out how I could find out when this logout has happened, I tried the following code:
var strUserName = '#{javascript: #Name("[CN]", #UserName());}';
alert("Start: " + strUserName);
It always returns the username rather than anonymous in window 1, even when user is logged out in window 2!
onError event never fires when partial refresh fails or returns blank value.
Any ideas or help would be greatly appreciated.
Did you try to lock the database down (Anonymous = NoAccess)? Then you should get an 404 and the error routine fires.
Update
You can:
add a redirect meta header to the page that kicks in when a session expires (cheapo solution, but might catch already most used cases)
Still lock down the database but give Anonymous the right "view public pages" and then have the page(s) that anonymous is allowed to see marked with the attribute "available for public access"
Make sure your partial refresh checks if nothing comes back and reloads the page then (most work since you need to alter business logic) - some sample of your code would be needed
onComplete has one weakness. The value bindings are evaluated when the page is rendered, not after a partial refresh, as you might think. This is due to the way the request works. When a request is sent, the callbacks for the request are bound (onStart,onComplete, etc.). Therefore the client side handler code has to be available before the refresh happens.
If the partial refresh doesn't refresh the item with the event handler(onComplete/onStart/onError), I think the value binding is only updated on page load.
There are several ways to solve this.
Have a client side function that does partial refresh on a hidden (by CSS) xp:text/etc. that shows the current user name. Fetch the content using theNodeReferenceVariable.innerHTML. If Anonymous is the current user:
document.location.href = document.location.href
You could also do document.location.reload(), but that might result in submits being resent.
Use the XPages Extension Library REST services. Same as above, if Anonymous, reload page.
Say we have an "add new object" form in AddObject.jspx, and a Confirm.jsp page (saying something like object with id NN was added to the database...)
in faces-config.xml:
<navigation-rule>
<from-view-id>/AddObject.jsp</from-view-id>
<navigation-case>
<from-outcome>add</from-outcome>
<to-view-id>/Confirm.jsp</to-view-id>
</navigation-case>
</navigation-rule>
So the user opens AddObject.jsp, fills out the form, and clicks the 'add' button that triggers an event handler in the AddObject's backing bean. The backing bean inserts the new object into the database and returns the "add" outcome. So we end up in the Confirm screen.
Now if I hit F5 (refresh the browser) a new object will be created and the Confirm screen redisplayed with the new ID of the new object. I can keep hitting F5 and get as many new objects as I'd like.
I don't want this. I want to detect such situations. Avoid adding the same object many times over (generating many rows in the database that differ only by ID).
Can I do this with JSF? Why does it ask me for from-view-id/outcome/to-view-id if it doesn't seem to make any good use of this information?
There are two parts to this problem.
First, you need to avoid having the broswer's refresh of the confirm page resubmit the request. So one approach if for the brower's history not to say
POST this request
and instead say
GET this confirmation page
We cam do that by using the
<redirect/>
statement in the JSF navigation. Now this means that a redirect response is sent to the Browser. The browser then ask JSF for the conformation page. NOTE: this is now a new request from JSF's perspective, so any data you want to display needs to be at session scope not request scope.
This "Use a redirect for actions that make changes" approach is quite a common idiom. However it doesn't address the "Quick Fire User" problem. What would happen if the user hit the "Submit" twice very rapidly? You can get to a situation where the browser has sent two requests. There are other scenarios where this can happen - network glitch on the first request, user gets impatient, sends the request again.
So we need somehow to handle such double submissions. This is not a JSF-specific problem. A typical solution is for the backend to send a token when the original request page is populated. This is held in a hidden field. When the request is submitted that token (some unique number) is sent back to the application which records that it has been used, hence a double submission is detected.
You can also use JavaScript in the browser to prevent double submission. This should give a friendlier user experience but I would not recommend relying only on Browser-side control. The server should have ultimate respsonbility.