How can I call liferay struts action from my own portlet? - struts

I define an editPortletURL
PortletURL redirectURL = renderResponse.createRenderURL();
redirectURL.setWindowState(LiferayWindowState.POP_UP);
redirectURL.setParameter("struts_action", "/asset_publisher/add_asset_redirect");
editPortletURL.setParameter("redirect", redirectURL.toString());
editPortletURL.setParameter("originalRedirect", redirectURL.toString());
editPortletURLString = editPortletURL.toString();
editPortletURLString = HttpUtil.addParameter(editPortletURLString, "doAsGroupId", assetRenderer.getGroupId());
editPortletURLString = HttpUtil.addParameter(editPortletURLString, "refererPlid", plid);
I call the edit_article.jsp from my portlet. I will, if I click on "publish" button, I should be forwarded to the jsp page which is pointed to /asset_publisher/add_asset_redirect struts action.
This action is mapped to the add_asset_jsp. This page fires Liferay.fire (closeWindow) event, which should close the popup window und refresh my portlet.
But If I try to do that - I see my portlet in the popup window...
How can I reference/include Liferay action classes into my own portlet?

If you are working in liferay 6.1 then you can simply use the action-hook to achive your requirment. Please check below links
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/other-hooks
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/performing-a-custom-acti-4

Related

How can i open a new route in a new page by clearing the previous homepage link. When i click submit the next page opens below the homepage

When i try to open a new route by clicking login button the new page named "hello" opens at the bottom of the login page instead of opening in a new page. How can i fix this?

How to switch Xamarin forms Main Page from Master Details Page to Content Page?

I am working on an Xamarin forms Application. In which on App.cs I check
CrossSecureStorage.Current.HasKey("SessionToken")
then navigate to HomePage() which is a Masterdetailspage and if no security token then I navigate to LoginPage() which is a ContentPage like this
if (CrossSecureStorage.Current.HasKey("SessionToken"))
MainPage = new NavigationPage(new HomePage(true));
else
MainPage = new NavigationPage(new LoginPage(this));
then when user clicked login button I set main page to HomePage() like this
MainPage = new NavigationPage(new HomePage(true));
and when user clicked logout button I set main page to login again like this
CrossSecureStorage.Current.DeleteKey("SessionToken");
MainPage = new NavigationPage(new LoginPage(this));
It works fine when user is already logged out. Login and logout both works fine. But if user was already logged in says
CrossSecureStorage.Current.HasKey("SessionToken")
has value then on logout button press app crashes and got this Exception
System.ArgumentException: Handle must be valid.Parameter name: instance
I figure out that if in App.cs I changed HomePage from MasterDetailsPage to a new ContentPage then on button press change MainPage to HomePage then it works fine but I want to directly show homepage to user. (Means if first page assigned to MainPage is a ContentPage then app works fine but if first page is a MasterDetailsPage then app crashes on reassigning MainPage to any Page.)
Please help.
Thanks in Advance.

Yii Framework CTabview Focus Issue

I am trying to navigate tab3(BaseContact Edit Source) from tab2 (BaseContact EditStructure) button,
Please refer below screen shots...
When you click on "Start Import" an action should be called in a controller.
In this controller, you should have a "redirect". You can pass an url argument (#) in your "redirect" to switch to an other tab.
Eg :
$this->redirect(array('offer/view', 'id' => $offer_id,'#'=>'tab2'));

single page application deep linking with login page

My team is going to build a single-page-application for our future project. At the moment, I have a problem with designing the app with login page. There are 2 approaches:
Create the login page as a separate page, the rest of the app is another single page.
The app has only 1 page and the login page will be a view in the app which is switched back and forth using javascript.
I don't know which approach I should take. I have read some discussions on the internet, it seems like it's more popular to create the login page as a separate page, the reason for this is we can use normal cookie-based authentication with session on server, redirect users to default page (main page) after successful login, and so on. Therefore, I'm thinking about creating the login page as a separate page, but I have a problem with deep linking.
For example, let's say I have 2 pages: login.html, index.html (main page). When an unauthenticated user requests a page like this index.html#product=1, the user will be redirected to the login.html, after successfully loging in, redirect the user back to index.html#product=1. But at this point, the #product=1 is lost.
Please advice me on how to keep the deep link or should I take the second approach?
Thank you
If you are building a single page app, it would be 'nicer' from the users point of view to have it all on one page, so I would suggest option 2.
Not sure if you need javascript to switch it though - you could use something like the following (PHP code)
At the start of the application saves what view the user is looking at and checks if the user pressed 'submit' on the login form
$selected_menu = $_GET['menu'] ;
//check to see if they've submitted the login form
if(isset($_POST['submit-login'])) {
If the login is successful, redirect them back to the same page with the appropriate view as a parameter
Then in the main page of the app when you are about to display data you would check to see if the user is validated, and if not then present the login form as part of the page.
$usr = CheckLogon();
if ( $usr == "" ) { // check for correct test to make sure user is logged on
ShowLoginForm();
....
I decided to go with approach 2: The app has only 1 page and the login page will be a view in the app which is switched back and forth using javascript.. I found out that it's not difficult to do and I can still use normal cookie-based authentication with session on server, redirect users to default page (main page) after successful login, and so on. Here is a sample code how I do it with angularjs.
Routing:
var App = angular.module('App', ["ui.state"]);
App.config(function ($stateProvider, $routeProvider) {
$stateProvider.
.state('login', {
url: "/login?returnUrl",
templateUrl: '/Home/Login',
controller:"LoginController"
})
.state('main', {
url: "/main",
abstract:true,
templateUrl: '/Home/Main',
controller: "MainController"
})
})
.run(function ($rootScope, $state, $stateParams, $location) {
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error){
if (error.status == 401) {
$state.transitionTo("login", { returnUrl: $location.url() });
}
})
});
The point here is when there is a route change error with status 401 (from the server) indicating that the user is not logged in, I will transition to login state with the return url.
After the user successfully logging in using ajax, I will transition the state back to my main view. Something like this:
$http.post("/Login", JSON.stringify({UserName:username,Password:password}))
.success(function (data, status, headers, config) {
var returnUrl = $stateParams.returnUrl ? $stateParams.returnUrl : "mydefaulturl";
$location.url(returnUrl);
})
With this approach, now I'm able to create deep-link to jump to a specific state in my app with login page and return url.

How do I get a link for a protected page and redirect the user to the login page?

In my Sitecore site I need a page viewable only to authorized users. I have allowed read and inheritance for the role I want and denied read and inheritance for extranet\anonymous. The item is part of a group where the other items are not protected. This list of items is databound and rendered as navigation links on the site.
var id = new Sitecore.Data.ID("<guid here>");
var item = Sitecore.Context.Database.GetItem(id);
// protected item is not part of Children collection when user is anon.
this.navrepeater.DataSource = item.Children;
this.navrepeater.DataBind();
When I'm logged in, a link to the protected item is shown and I can view the page. When I'm not logged in (operating as extranet\anonymous), the link is not shown at all. When I go the url directly I get a 403 error. In my web.config I have set the loginPage attribute on the site node but I don't get redirected.
<site name="mysite" ... loginpage="/login.aspx" />
So,
How do I display the link to the protected page for anonymous users
How do get sitecore to redirect the user to the login page when needed
1) You can wrap the code that retrieves the items for the nav links in the SecurityDisabler to show the link even if they can't view the page:
using(new SecurityDisabler()) { // this bypasses any security
this.navrepeater.DataSource = item.GetChildren(); // note that the Children property is deprecated, use the GetChildren() method instead
}
2) If you make your page's code behind class inherit from Sitecore.Shell.Web.UI.SecurePage it will handle the check and redirect to the login page for you. No coding needed.