Basically, I am creating a site which will be accessible via Mobile and desktop. So i want to create 2 views.
My action code remains same. Everything else is same. Just jsp changes for both. How i can do this via struts 1/2 ?
You can also do this by adding third party jar "deli.jar" and using its Profile, Workspace etc. class to detect the type of mobile from which the url is being requested. In struts you can make the page viewed by Mobile user by making it in xhtml, as follows
<html:html xhtml="true"
But this will only supported for the mobile which have xhtml enabled browser.
Hope this will help you.
You will need to pass in a query parameter or something in the header which will distingush between the 2 requests. For example: http://yoursite.com/render.action?type=mobile.
Finally in your action:
if ("mobile".equals(type)){
return "mobile";
}else {
return ActionSupport.SUCCESS;
}
In your struts have a new result-type
<result name="success">/WEB-INF/jsp/somethign/web.jsp></result>
<result name="success">/WEB-INF/jsp/somethign/mobile.jsp></result>
Related
Quite new to Sitecore, I am building a Sitecore web application with no authentication (anonymous). It's a large project with lots of hierarchical top, side menus.
When the user revisits the website, I need load the page that was last visited with menu item highlighted. Could someone please help me whether there's any Sitecore API that provides this and if not what would be the ideal solution i.e. store last visited page on client cookie?
An option I can see would be storing the last visited page on client cookie like you said, then build in a custom processor and put it in the
<httpRequestBegin>
pipeline in the web.config.
A custom processor needs to inherit from the HttpRequestProcessor class, and you'd need to override the Process method.
What I would suggest in this case is having your custom processor like this:
<processor type="Your.NameSpace.ClassName, Your.Assembly" />
<processor type="Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel" />
and have something like the following:
namespace Your.Namespace
{
public class ClassName : HttpRequestProcessor
{
public override void Process(HttpRequestArgs args)
{
// Get cookie:
var cookievalue = WebUtil.GetCookieValue("cookiename");
WebUtil.Redirect(cookievalue);
}
}
}
Of course this suggest you'll store the URL of the last visited page in the cookie. You could also store the ID of the last visited item in the cookie of course, and get it's path from there.
I just came across this article, and as Holder mentions, it should be possible to get the information from DMS if you have it enabled and are using it:
Get last visited pages from a Sitecore DMS (OMS) Profile
As far as I know, there isn't anything in the default API that does this.
There might be something in Sitecore OMS, but I don't know much about OMS.
I think a cookie, might be the easiest and simplest way of doing this.
I have a grails webflow that works fine for my desktop browser app. Now I'd like to reuse the webflow for my mobile site. I'd prefer not to have 2 separate webflows and just change the pages that are used for each state. I tried the following:
viewState{
String view = 'viewState'
boolean isMobile = this.isMobileUser()
if(isMobile){
view = "/flowDir/mobile/viewState"
}
render(view:view)
}
However this isn't working. If the mobile site is accessed first then the desktop will get the mobile pages and vice versa.
Has anyone encountered this problem? I'd really hate to have 2 webflows that do the same exact thing. I'd also hate to hack into Sitemesh. Any ideas or suggestions on how to reuse this flow would be greatly appreciated.
Try putting the mobile view resolution into an after filter so that your web flow executes the same, but you intercept the view being rendered and rename it.
http://adammonsen.com/post/548
I agree with droggo that responsive design is the best solution.
However, as an alternative, you could potentially have all webflow users going to the same view, but within that view itself you could override the g:layout taglib with a taglib of your own that is able to determine whether you're running as a mobile user or not, and hence can apply an appropriate layout.
It's maybe a little heavy handed in this context, but it would give you a solution that would be reusable across your entire app, not just within webflow, and it keeps the mobile-specific code in one place.
So in your webflow:
viewState{
String view = 'viewState'
[snip] The rest of your code goes here
render(view:view)
}
Then your view:
<myapp:applyLayout name="someWebflowLayout">
[snip] Your non-layout GSP code goes here
</myapp:applyLayout>
Then your taglib:
class MyAppTagLib {
static namespace = "myapp"
def applyLayout = { attrs, body ->
boolean mobileUser = false
[snip] some logic to determine if this is a mobile user or not goes here
if (mobileUser) {
attrs.name = "mobileLayout/${attrs.name}"
} else {
attrs.name = "desktopLayout/${attrs.name}"
}
out << g.applyLayout(attrs, body)
}
}
You would then have two layout files called someWebflowLayout - one within /layouts/mobileLayout and one within /layouts/desktopLayout (although I appreciate these might not exactly match your existing structure)
The code in the taglib above is only a rough guide, and it'd need bolstering to deal with the other parameters that g:applyLayout takes.
Is there a way to navigate previous page from grails Controller and pass model to be rendered, for example I'm having page and want to navigate user/register and to revert to the previous url if there are errors in form?
currently I'm having
def register = {
...
return [user : user]
}
Thanks,
Mika
It looks like you're writing a webflow
Webflows are really the only game in town if you need to manage non-persistent state across multiple pages. Fortunately, webflow provides built-in support for your requirement - going back to the form page if validation fails.
My question is:
I have one pop up window to validate some content, and i use action class to do the validation(javascript not allowed). If the content is valid, i need to close this pop up window, and update the content in the main page.
My idea is in my struts.xml, i mapped
<result name="add" type ="redirectAction"> mainpage.jsp</result>
is it possible to add
<result name="add" > popupCurrentPage.jsp</result>
to let the same action result leads to two diffent pages at the same time?
Browsers may receive a single response for any request.
Doing multiple things on the client side based on a response requires JavaScript somewhere.
Use it's possible to add the tag in main page.
<s:include value="popupCurrentPage.jsp"/>
but when you are redirecting you will miss the valuestack data, so use messageStore interceptor.
I added a filter in my struts 2 application. I am using this filter to check cookie values. If appropriate cookie is found then i want to redirect user to home page rather than normal login page.
So for displaying home page I want to call struts 2 action associated with home page.
I tried calling homepage.execute() method from filter, but this does not display the result(jsp page) associated with home page.
Please suggest me some way to call homepage action from fiter class.
I don't know what your requirements are, but usually using a Struts 2 interceptor is a better idea.
Anyway you can't invoke action directly from Java because it would not trigger the framework stuff. Instead you should consider to redirect to the mapped url of the action (for example: response.sendRedirect("http://your_host_name/your_action_name.action") )