JSF 1.2 : Redirecting to a different portlet from phaselistener - jsf-1.2

Am using JSF 1.2
In phaselistener of one portlet, if some condition matches, I want to redirect to a different portlet altogether. I have the below code in beforePhase method
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect("/my-other-portlet-url");
Its not working. Even I tried putting it in afterPhase method. Didnt work.
What is the right way to do this? Can redirection be done to another portlet in my scenario?
Regards,
Vikas

Try
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler handler = context.getApplication().getNavigationHandler();
handler.handleNavigation(context, null, "my-other-portlet-url"); //put there name of your page
This should work even from PhaseListener

Related

MVVMCross BindingContext is Null when not using MvxContentPage

I have an issue where several of my pages are using the SfBackdropPage control from Syncfusion. This control requires the page to have a base of SfBackdropPage and not the usual ContentPage otherwise it just won't work.
To make MVVMCross work, the page needs have a base such as MvxContentPage
You see where this is going ?
I opened a ticket with Syncfusion to see if they could work around this issue but basically they just said its not possible. So since I needed to have that control as part of the page I had to leave the base as it was.
How do I setup MVVMCross to work with these pages without having the page inherit from MvxContentPage ?
I've used the following in the setup.cs in the Android project:
protected override IMvxViewsContainer InitializeViewLookup(IDictionary<Type, Type> viewModelViewLookup)
{
viewModelViewLookup.Add(typeof(SitesViewModel), typeof(SitesView));
return base.InitializeViewLookup(viewModelViewLookup);
}
I can navigate to the page but I get a null reference exception due to the binding context not been set. I've tried to set this in the XAML but it requires a parameterless constructor but that's not possible as the view model uses Dependency Injection as it relies on these object been passed in.
Can anyone give any pointers, I'm still learning MVVMCross so hopefully I've just missed something.
XF: 4.8.0.1687
MVVMCross: 7.1.2
UPDATE 1:
I've tried to find something in the MVVMCross source to see how it does the setup for the binding context, but I've not found anything. So for now, I'm manually creating the binding context in the page code behind and using Mvx.IocProvider.Resolve<> to pass the required interfaces.
I'm not sure if this is the best to workaround this issue but it works. Maybe there is a better way ?
UPDATE 2:
It seems that update 1 route is no good as the doing this creates a new instance of the VM which is to be expected but an instance already exists which is created by the MVVMCross framework. The question is how do I get the VM instance from the code behind ? The only way I have found so far is to use IMvxOverridePresentationAttribute and the cast the request to MvxViewModelInstanceRequest which then allows access to the VM instance which I assign to the binding context. I may be better off creating another question as to the best approach for this method.

URL for new views in MVC4

I've seen several MVC4 tutorials that show how to access the index URL for a view, but I can't seem to reach a new view that I add.
I can access my home index at:
http://localhost:3214/
But if I create a new view (let's call it "NewView.cshtml") I can't access it from
http://localhost:3214/NewView.cshtml
Where would it be?
The page inspector expects the page to be at:
http://localhost:4244/Home/NewView
But it isn't there.
UPDATE:
In the solution explorer the file is located at:
MyProject/Views/Home/NewView.cshtml
OK - So think of your Views as merely html files (although they are not) - i.e. they are purely for display purposes. But they are not static like normal HTMLs - they have code.
Hence its the controller and the route that you need to understand.
The route is what you type in the browser. For instance /Home/NewView will be translated to HomeController, NewView action if thats how you have configured it. The default view is {controller}/{action}/{id} so try http://localhost:4244/Home/NewView/1
Now to properly display and code NewView you need to go to your HomeController and add a NewView action. Like:
public ActionResult NewView()
{
return View(); // This will automatically display the NewView.chtml view from the Home (or Shared) folder in your Views folder
}
Then go to your Routes (typically in your global.asax file and add it like:
routes.MapRoute(
"SomeUniqueRouteName",
"Home/NewView",
new { controller = "Home" action = "NewView" }
);
Then you can call it like http://localhost:4244/Home/NewView without the id cause you haev specified a route for it.
Let me know if you need any more help.

call mxml from actionscript

I am very new to Flex & Action script and here is my requirement:
There is one boolean flag in action script and if flag value is true then redirect to success.mxml page and if flag value false then redirect to error.mxml page.
Can anyone suggest me, how to redirect to mxml page/componenet from action script based on some condition.
MXML files are Actionscript class files. They are not pages as in JSP.
Although you can add both success.mxml and error.mxml as a child in Application tag and depending upon your flag value, you can set visibility of either to true or false.
Please Learn some Flex tutorial or book first because this question is too basic to answer.
You have to create the two variable with data type of both the mxml.
so as you your flag is true, just create a new instance of that variable and you can also call its all the public variable/functions for you as file. You also call their layout objects if you given them id's.
It is not bound in the Flex. You can call anything form anywhere if not then try Events.
Try to learn the flex tutorial for that. You can also try the Tour de flex.
Regards,
Manish

How to get the current view name in asp.net MVC 3?

How can I get the current view name regarding to current URL, in asp.net MVC 3 using Razor engine?
No idea why you would need to get the current view name but you could use the VirtualPath property inside a view. Normally it's more useful to know the current action or controller. But anyway, here's how to get the current view name:
#VirtualPath
and if you wanted to get only the filename:
#Path.GetFileName(Server.MapPath(VirtualPath))
and without the extension:
#Path.GetFileNameWithoutExtension(Server.MapPath(VirtualPath))
I've also tested this code, and I could do something with it.
But, I'm not sure if is this a good solution or not.
For example, I need to detect the Contacts view located in Home directory. So I wrote:
if (#Request.RawUrl == "/Home/Contacts")
{
// do something
}
You can get it from RequestContext.RouteData
specifically, its Values collection contains "controller" and "action" keys
i.e.
RequestContext.RouteData.Values["controller"]
RequestContext.RouteData.Values["action"]
ASP.NET Core's equivalent:
#ViewContext.ExecutingFilePath
Output is like this:
/Views/Shared/String.cshtml
The rendering of a view may involve one or more files (e.g. _ViewStart, Layouts etc).
This property contains the path of the file currently being rendered.
ViewContext.ExecutingFilePath Property

Connecting An <a> tag to a ViewController mvc

I know this is probably straight forward, but this isnt working for me, I want to simply connect this to trigger a viewController when I click it. When I create a controller and a view and click it it throws a 404 and the code never hits the controller.
<div> All Accounts In the System</div>
You should probably follow few tutorials for mvc. Links are by default using System.Web.Routing magic (if you have default template, look into global.asax). Default url looks like /controller/action/id where id is optional, action defaulted to Index and controller defaulted to Home. For link construction in views use these helper methods:
#Html.ActionLink("All accounts in the system", "AdminReports", "Admin");
or
All accounts in the system
The link should look like /Admin/AdminReports with default settings.
You want something like this:
<a href='<%= Url.Action("Controller", "Action") %>'>Text</a>
where
Controller = Your controller name.
Action = Your action method.

Resources