Enable an interface in the background - jsf-2

I want to know how to put an interface where there are buttons and links in the background, in disabled mode, then it is reactivated after user authentication?
That is to say, when the user authenticates, the page in the background is active .
I use JSF and PrimeFaces.
Thank you in advance for your help.

Do you want to have effect like on this demo ?
http://www.primefaces.org/showcase/ui/confirmDialog.jsf
That's called overlay, and you can create it in primefaces, or in jquery, but that demo should do the work.
You need to know that when you create such overlay someone might open firebug and just remove overlay element and operate on site content.

Make use of disabled attribute of a JSF command/input component. It accepts a boolean expression.
E.g., assuming you're using container managed authentication to login (and thus, the logged-in user is available via #{request.remoteUser} in the view):
<h:commandButton ... disabled="#{not empty request.remoteUser}">
As you're using PrimeFaces, an alternative would be to use its <p:blockUI> component. See also its showcase for a concrete example.

Related

How to open a vaadin combobox programmatically

I have implemented a poor-mans-searchbox using a combobox. The search expression is typed into the textfield and the user press enter. Then the search expression is added to the combo model, this is caught in the eventhandler which then runs the search, empties the combo list and populates it with the searchresults instead. However, the user then need to open the combo list manually (by pressing the little down-arrow) to see the result. It'd be nice to open the list automatically, but I haven't found out how to do that. Does anyone know?
Also the search should be performed each time the user presses a key, and not only after enter is pressed.
Not as the poor man's solution, but you may extend the client side to do that. Tipically, the client side widget would have some method like "openResultsBox" or something similar. You could call that to open up the box. Vaadin 7 also allows you to write extensions which basically lets you extend the client side for exactly doing the very same slight changes. I am not sure why you have chosen the combobox for that though.
the vaadin-combo-box component offers a method called "open" so simply call
reference-to-element.open();
Should do the trick.
Relevant official docs here:
https://www.webcomponents.org/element/vaadin/vaadin-combo-box/elements/vaadin-combo-box#method-open

JSF2 - reset ViewScopedBeans when Navigating to other page/tab

I'm working with a Liferay portlet with JSF2 and Primefaces.
A lot of my Backing Beans are SessionScoped, as they are keeping info needed from multiple pages of the same portlet, and I want them to keep this info for the whole session, so I can't turn them to ViewScoped.
This way, the user has to log-out and log-in to reset the Backing Beans, and this is the supposed behavior I wanted. But I'd like to reset them when the user navigates to another portal page. So, my question is, what is the most convenient way to do this ?
Is there some Event I could catch when changing the page, and call some custom reset function on the Portlet?
Maybe some default setting on the portlet that will automatically reset the beans (no custom reset functions) ?
Any other Ideas ?
thanx!

jQuery Mobile dynamic application and history-based navigation

I want to implement a jQuery Mobile application without browser history navigation (feel free to ask why). I can generate pages on the fly, insert them into the DOM, and bring them up with changeHash set to false, then clean them up in the pagehide event handler, and all is well in the world. Until I use a widget like selectmenu that invokes a dialog. The dialog's close function explicitly invokes window.history.back(), and my world implodes.
Is there a simple workaround for this issue?
If not, should jQM be adapted to gracefully support nav-less apps, or is jQM fundamentally unsuited for this kind of application?
http://jquerymobile.com/test/docs/api/globalconfig.html
Try setting hashListeningEnabled to false
I learned not to use changeHash=false for this purpose. Make sure that the current page is always at the top of the history stack. In my case, it's the only item on the stack except when dialogs are invoked. So far, this seems to be working like a champ:
function showNewPage($page) {
$page.appendTo($.mobile.pageContainer);
$('.ui-page-active').bind('pagehide',function(){$(this).removeWithDependents()});
$.mobile.changePage($page);
$.mobile.firstPage = $page;
}
The new page is created without a hash, so the URL never changes. Since I'm actually replacing the first page, I had to update $.mobile.firstPage. The call to removeWithDependents() instead of remove() cleans up the dialogs that are created by selectmenu.
Fortunately, it's a lot more concise than I anticipated, just a bit of a pain for a newcomer like me to piece together. I've seen a few comments advising not to "hack" jQM in this way, but I think there's way too much value in jQM to constrain it to a traditional server-dispensed presentation model.

Make checkbox as a link?

I want the html.checkbox() in ASP.NET MVC to be as a link that goes to an action controller (GET and not POST).
Question:
It is possible to make the html.checkbox() to act as a "actionlink" instead of going to the FormCollection without using Javascript and JQuery or any additional plugin?
This wouldn't be possible in any framework as checkboxes are just static input elements. They have no ability to trigger any sort of action on their own, hence where javascript and event handlers comes in.
You could try making a form who's method is GET, but it would still have to go somewhere.. I guess you could make an action that handles various states of a checkbox and then routes to the correct page, however you'd still need to submit this form by having the user click a submit (again because the only way to trigger an action from clicking a checkbox is by using javascript)
You could also fake a checkbox using css and checkbox-like images.
text goes here
If you need to show it as either checked or unchecked, you would use two classes with two different checkbox-like images.
I doubt this is possible without javascript.
Except for buttons and links, no controls actually do anything but change their own value in the DOM.
It would however be rather trivial to add an onclick to your checkbox that would do whatever (including a GET request).

Disable link if user is not allowed to access target

I have created an ASP.NET MVC application and created different kind of roles for my users. I have then created different kinds of AuthorizeAttributes for allowing/disallowing access to different Actions in my controls.
However I have got a lot of links that points to different of theese actions that are restricted for different roles. Can you somehow fix so that theese links get disabled automatically? I could of course add a lot of UserIsInRole(....)-stuff in my code but I really would prefer not to if there is a better way.
Du you have any suggestions?
Are they in a list or menu? Is this something your controller could pass to your View? you could pass out a list of all allowed (or forbidden, whichever is more appropriate) and check that before you display a link.
if (allowedLink.Contans(myLink)
// show enabled link
else
//show disabled
The other good way would be to override the HtmlHelper for ActionLinks and make it do the check for permissions for you. Then if they do not have permissions, your html helper would display it disabled.
For examples, see this link http://www.asp.net/learn/mvc/tutorial-09-cs.aspx
Off the top of my head...
• You can set the onClick action for each link to do nothing.
• You can set the URL for the link to "#", which does nothing.

Resources