Programmatically set active-menuitem of PrimeFaces responsive themes - java

We're using one of the new responsive themes of PrimeFaces 8 (Mirage if that matters) I've implemented a dynamic menu to create the menu of my page. Depending on several parameters, the landing page can be different. Example:
Suppose there's a communications environment in which the menu items are
Documents (opens by default)
E-mail
Pictures
When arriving in the communications environment, the application checks whether there are new e-mails. If so, the user won't arrive on the "Documents" page but on the "E-mails" page.
The theme uses cookies to restore the menu state based on what the user has chosen previously. So suppose last time (s)he has chosen "Pictures", the result now is that the menu item "Pictures" is marked as active-menuitem but the displayed page is "E-mail".
I was already able to clear the cookies so that no menu item is active, but now I'm trying to activate the correct menu item. I got most successful by calling
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('li'));
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('ul').closest('li'));
but since the page is rebuild using ajax, this only works once 🤨. Using the build-in .active-menuitem doesn't work so that's why I introduced .custom-active-menuitem that I set in Java code:
DefaultMenuItem.builder()
.value("E-mail")
.icon("fa fa-letter")
.command("#{communicationBean.openEmailPage()}")
.styleClass("custom-active-menuitem") // or something else to mark this item active
.process("#this")
.update(":page");
So now I'm puzzled. Can someone please get me in the correct direction? How can I make the theme show the menu item I choose as active one?

Related

Programmatically add the created item name to the site page url

I have site pages with structure like this:
/Collections (main page that appears on main navigation menu)
/Add Collection (child page that appears as a drop down (hover) on main navigation menu)
/General Information (child page of Add Collection that appears as tabbed sub navigation menu below main navigation menu. After adding the collection, I redirect to this page.)
So the idea is to add a collection, redirect to the General Information page where I show the information about that added collection.
The first and second level pages have theme1, while the third level page "General Information" has theme2. In the site administration, this third level page has friendly url http://localhost:8080/web/guest/collections/general-information
and this is what I am trying to modify programmatically.
In the portlet class after creating a collection, I append id parameter to this friendly url
response.sendRedirect(themeDisplay.getURLPortal()+"/collections/"+"general-information?id="+id);
and in the theme2 and jsp, I get this id to display the General Information of appropriate collection.
What I want to do is perhaps modify the friendly url programmatically and accomodate the collection name in this url. Something like:
http://localhost:8080/web/guest/collections/{collectionname}/general-information
How can I do this?

how to stop spring security timeout from loading my login page in a div

I am having an issue with spring security's timeout facility. On my home JSP i have a table. each list item will allow the user to modify the data in this list element. when you click the edit icon a modal opens with the data from that list element so the user can edit it. the issue I am having is if this modal is open and the system times out and loads the login page. but it loads the login page into the table div. I am just wondering if anyone knows of any possible solutions to this problem?? I have increased the time out limit but will not fix the problem of the login page being displayed in my table div. any help is much appreciated.
hanks in advance Billy
You might need to check via javascript if the returned page is a login form and in that case open the proper login page, then retrieve the original url after a successful login.
An example is here: http://gal-levinsky.blogspot.it/2011/08/spring-security-3-ajax-login.html

Android, YUI, Moodle

The problem I'm having is the following:
I have an app with two separate modes: A WebView for browsing and a custom Canvas. The custom Canvas captures handwriting samples for language placement exams. Here's how it works. A user logs in to Moodle via the WebView. After they log in, they navigate to a Quiz inside Moodle. They click a link on one of the Quiz's questions and this launches an Intent which hides the WebView and shows the Canvas. The user then writes (using a stylus) on the Canvas. When a user is finished writing their essay (or whatever), they press a button that uploads an image file to Moodle. I am able to upload images to a point, it's getting them to show up in the HTML page that the user clicked the link in originally (see above) and to get Moodle to commit them to permanent storage that is the problem. Normally this is all accomplished through AJAX (really AJAJ since it's JavaScript and JSON) and when the user drops a file on this one component, the component refreshes and uploads the file.
Here is the problem: I need the WebView so that students can log in to Moodle through Shibboleth. But because the underlying JavaScript in the browser makes AJAX calls to the Moodle server and since the Java side of Android doesn't have access to the DOM, I have use the Apache HTTP components library to make some of the connections below basically to preserve the state of the HTML page in WebView.
In a desktop browser on, say, Windows, I use WebScarab to monitor the browser's requests and this is what I see: the browser uploads a file to Moodle via five successive calls to the following scripts:
POST https://[moodle website]/repository/repository_ajax.php [posts multipart form data]
POST https://[moodle website]/repository/draftfiles_ajax.php [posts some params]
GET https://[moodle website]/draftfile.php/[some_id]/user/draft/[some_id]/[somefilename.png] [returns an icon of the image for a filepicker from YUI]
POST https://[moodle website]/mod/quiz/processattempt.php [returns HTML page]
GET https://[moodle website]/mod/quiz/summary.php [returns HTML page]
Some of these scripts return, as you'd expect, JSON data since they're AJAX and not HTML. The final two calls (4 & 5) return HTML. Now, I can make all of those calls in succession in either the WebView or the Apache HTTP library, but if I do so with WebView, only JSON data is returned to the WebView in calls 1-3 (WebView treats the JSON data as a page and displays it wiping out whatever HTML page was displayed in it). If I capture and process the JSON data using the Apache HTTP library in Java, then the JavaScript components internal to the page do not get updated. If I split the calls so that I send only calls 4 & 5 to the WebView, the HTML merely returns WebView to the first question of the exam and Moodle acts as if I haven't uploaded anything.
I can verify that files are uploading if I manually refresh (press a link) the JavaScript UI elements in the page. I can't expect students to do this, though, because the link to do so is very tiny and it's not obvious that it does a refresh. I need a way to programmatically refresh this one element (it's part of YUI) or to get Android and the Java side to play more nicely with the JavaScript/DOM side.
My question is: does anyone know a way to 1) fire off a drag and drop event using YUI to an element inside an HTML page or 2) a way to consume the JSON data and pass it to an element inside the HTML page.
I'm banging my head against a wall trying to figure this out.
OK, so I figured out that: javascript:document.getElementsByClassName(\"[name of link here]\")[0].click() works in Chrome on the desktop but doesn't work if I pass it to WebView.loadURL(). I just need to be able to simulate that click event reliably in WebView. It appears not to support click(). Anyone have any ideas?
The winning code is:
el = document.getElementsByClassName("[some element]")[0];
var event = document.createEvent("MouseEvents");
event.initEvent("click", true, true);
el.dispatchEvent(event);
This selects the link at [some element] and thereby fires an AJAX request that refreshes the FilePicker. For those working with Moodle, I had to add the above code to the same quiz question that handles so it is invoked by putting that code in its own function and calling it with WebView.loadURL("javascript:myRefreshFunction()").

How to display success message after redirection to another JSF?

After a customer is successfully added in my JSF application on the page add_customer.jsf, the user is redirected to the page list_customers.jsf.
On this page I would like a success message to be shown. The message should only be shown if the user is really coming from the add_customer.jsf page.
How can I do this?
One approach is to add a message to The Flash in the action method that adds the customer.
You don't need to explicitly check that the user was coming from add_customer.jsf, if it's that page (or actually the code behind it) that sets the message. On the destination page you only need to have an <h:messages> component.
A co-worker of my posted an example CRUD app that does exactly this at: Sample CRUD application with JSF.
The relevant code is in the backing bean UserEdit and the page where the redirect happens to.
Note that if your JSF implementation is Mojarra, The Flash only works between pages in the same directory. If this bothers you, please consider voting for this issue: http://java.net/jira/browse/JAVASERVERFACES-2136
The best way to do it would be using a <h:message> tag with which you could bind a message which can be populated before you redirect to list_customer.jsf.
We have been using this approach for showing messages in our application from last 3-4 years and occasionally used partial triggers to refresh on the same page.

how to handle refresh mechanism in GXT MVC

HI,
How to retain the current state of the application with all the opened tabs and loaded grid when user does browser refresh or f5 in GXT using MVC pattern?
Regards,
Srini
One approach is to set browser cookies so that browser state can be restored at a later point.
Construct the grid/tab panel
Set a cookie with the current paging settings or open tabs
When the paging settings change or when tabs are opened/closed, update the cookie
Now that you're setting cookies, update step 1 so that you construct the grid/tab panel using settings you read from the user's cookies. Of course, if no cookies are set, use the default settings (grids start on page 1; no tabs open in the tab panel).
If you are using a fairly strict separation of concerns in your MVC pattern, the setting and updating of cookies should occur in the controller layer. The cookies themselves are another source of model data, and the view (UI widgets) need not understand why tabs are open or why the grid starts on page 3.

Categories