Ignore the slash in Magento <url> - url

I’ve created a menu in page.xml and it looks like this:
<reference name="primary.menu">
<action method="addLink" translate="label title">
<label>Test</label>
<url>test.html</url>
<title>Test</title>
<prepare>1</prepare>
<urlParams/>
<position>10</position>
<liParams>dark-gray</liParams>
<aParams></aParams>
<beforeText></beforeText>
<afterText></afterText>
</action>
...................
The class used for the primary.menu block is extending the Mage_Page_Block_Template_Links class from Magento’s core.
The problem is, that when I click this link it goes to ‘www.mydomain.com/test.html/’ which is not working. My question is what should I do in order to stop the last ‘/’ from showing in the url?

I think that <prepare>1</prepare> is building your URL query (in the absence of a dedicated helper to supply the URL) and as a result is prefixing your URL with the domain (which is what you want), but it is also appending a trailing slash (which is what you don't want)
Either create a helper to supply the "proper" URL.
If the page is a Magento CMS page, use that helper (preferred)
Use <prepare/> and <url>/test.html</url> (hack alert!)
To use a Magento CMS helper to add a link
<action method="addLink" translate="label title before_text" module="cms">
<label>Test</label>
<url helper="cms/page/getPageUrl">
<page_id>1</page_id>
</url>
<title>Test</title>
<prepare/>
<urlParams/>
<position>10</position>
<li/>
<a/>
<before_text/>
<after_text/>
</action>

Related

Hide directory from URL

I am new in Struts. When I create my first Struts project and run it then URL of the project is the following:
10.1.21.85:8080/shravan/aboutus/about.jsp
But here in URL all paths of JSP pages display i.e my about.jsp page is inside shravan/aboutus folder so how I hide this directory structure in the URL?
First you should keep your JSPs private by putting them inside WEB-INF directory.
Then you have to map an action in struts.xml to show the desired jsp.
<struts>
<package name="default-package" extends="struts-default">
<action name="about-us">
<result>/WEB-INF/jsp/aboutus/about.jsp</result>
</action>
</package>
</struts>
And now your url should look something like this:
http://10.1.21.85:8080/shravan/about-us.action
You have to check in web.xml how is your struts configured to map the urls.
It could be:
/*.action, /*.do or simply /*

Where to edit footer links Magento 1.9

I'm trying to figure out where to edit footer links in magento 1.9 but I couldn't find anything I'll be searching it for almost 3hours but no success. Sorry I'm just a newbie in magento.
I want to edit the links under "QUICK LINKS" "ACCOUNT" I found the link under company and it's in magento backend under static blocks but no success for the two.
Thanks
These links are added in multiple layout files. The easiest way is to do a directory search (in your IDE) for "footer_links" phrase on the "layout/*.xml" files. You'll see that some links are being set in sales.xml, customer.xml or cms.xml. At the bottom of sales.xml for example you should see something like this:
<default>
<reference name="footer_links2">
<block type="sales/guest_links" name="return_link"/>
<action method="addLinkBlock"><blockName>return_link</blockName></action>
</reference>
</default>
This tells Magento to add the "Orders and Returns" link to the "Account" block in the footer. If you change the footer_links2 to footer_links, this link will end up in the "Quick Links" block. I think once you find this, you'll figure out the rest.
The other links and title are set via layout system:
page.xml:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
<block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
<label>Page Footer</label>
<action method="setElementClass"><value>bottom-container</value></action>
</block>
<block type="page/switch" name="store_switcher" as="store_switcher" after="*" template="page/switch/stores.phtml"/>
<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml">
<action method="setTitle"><title>Quick Links</title></action>
</block>
<block type="page/template_links" name="footer_links2" as="footer_links2" template="page/template/links.phtml">
<action method="setTitle"><title>Account</title></action>
</block>
<!-- This static block can be created and populated in admin. The footer_links cms block can be used as a starting point. -->
<!--<block type="cms/block" name="footer_social_links">
<action method="setBlockId"><block_id>footer_social_links</block_id></action>
</block>-->
</block>
Then in catalog.xml links are added:
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map"><label>Site Map</label><url helper="catalog/map/getCategoryUrl" /><title>Site Map</title></action>
The links are available on Admin menu -> CMC -> static block
Here available Footer Links, and repalace/modify the required links.
on CMS/pages you can find an option to edit the footer whatever you want.
Bro, You can create your a custom static block and add it to your footer, just replace the old one. Hope that helps..cheers..
Hi it can also simple.
Paste in your style.css from your themes.
ul.links { display:none}
or on another class from the first block. And make new links in your first block in the admin by statisch block.

url links in struts2 tiles gets namespace added on second time after click. How do I stop this?

I am using struts 2, tiles, and namespaces and am having a problem that after I click a link the menu appends the namespace a second time. I am using the struts tag url with an action and a namespace. When the page is first displayed, the links in the menu are correct land have the namespace before the action. After I click on one of the links, the page redisplays and although the source looks okay, when I hover over it firefox shows the url with the namespace in there twice. I.E.
localhost/ar/customermaint becomes localhost/ar/ar/customermaint. If I have clicked on a link that has a different namespace such as "ss" first then it becomes localhost/ss/ar/customermaint.
any idea what I'm doing wrong? Or is it a problem with tiles and namespaces.
I had faced this issue before. Each time when the action is called, the namespace gets appended in the URL and it looked ugly
Example: http://localhost:8080/RmAirlines/user/user/user/user/user/login for calling the action login from a namespace user each time
Setting the namespace to "/" isn't an ideal solution either.
Solution: Suppose the namespace of the package is "/user" and there's an action named "login" inside it (in your struts.xml). Then where ever you call the action, refer it as action="/user/login" (or action="/user/login.action") - i.e. putting a "/" before the namespace will save your day!
Example:
struts.xml
<package name="userManagement" namespace="/user" extends="struts-default">
<action name="login" class="com.rm.airlines.action.Login">
<result name="success">/user.jsp</result>
<result name="login">/login.jsp</result>
</action>
</package>
login.jsp
<s:form action="/user/login">
<s:textfield label="Email" key="email" />
<s:password label="Password" key="password" />
<s:submit />
</s:form>
To avoid this, always follow a simple principle.
For all namespace declaration, use a slash "/" followed by the namespace name.
In this way, it will not append the earlier namespace in new url.
What struts assume, if you don't specify "/" in new namespace, it tries to find it in currently used namespace. If you specify "/" before namespace name, it takes it as a root namespace.
Example:-
<package name="default" namespace="/nsp" extends="struts-default">
<action name="validate" class="login.LoginAction">
<result name="success">/home.jsp</result>
<result name="login">/login.jsp</result>
</action>
</package>
<package name="cricket" namespace="/cricket" extends="struts-default">
<action name="findcaptain" class="cricket.CaptainAction">
<result>/showCaptain.jsp</result>
</action>
</package>
Look in each of my package declaration, I am using namespace name prefixed by a slash. i.e. /nsp and /cricket). And that's how we could avoid this namespace appending issue.

In Struts2 HOWTO handle a url with same namespace but with or without the trailing slash similarly

In struts2 I am writing an app where I need to make sure that the url redirection works the same whether or not there is a trailing slash at the end.
E.g. example.com/app should behave same way as if user entered example.com/app/. Currently I changed mapping in struts.xml like so -
<struts>
<package name="default" namespace="/" extends="secure">
<interceptors> ... <interceptors>
<action name="app">
<result type="redirectAction">/app/</result>
</action>
</package>
</struts>
and
<struts>
<package name="app" namespace="/app" extends="secure">
<interceptors> ... <interceptors>
<action name="" class="com.example.action.app.LoginAction" method="display">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<interceptor-ref name="basic" />
<result type="redirectAction">home</result>
<result name="display">/jsp/base/content/login/loginForm.jsp</result>
</action>
</package>
</struts>
But this seems hackish since if I go to example.com/app it will show example.com//app/.html in the URL.
Any help appreciated.
Answer was derived in comments under the answer.
Quaternion:
Personally I would write all my urls with out the trailing slash...
and then I would use something external to the application to rewrite
urls as appropriate, perhaps iptables could determine if there is a
trailing slash and if so always strip it.
Mohana Rao SV:
As suggested above follow without tailing slash. And override
StrutsPrepareAndExecuteFilter one of the filter job is from the url it
has to identify the namespace and action name and invoke respective
action. So here remove tailing slash from url.
Quaternion:
In namespace "/" you have an action called app. That is all there is
to it to invoke CONTEXT_ROOT/app (that is what struts2 expects), you
don't ever expect to see a "/" on the end of the url, so you want to
find a method that parses the url before struts2 resolves the mapping.
What you have described only requires something to remove a trailing
"/" if it exists. I'd look to iptables because I've used it before or
some other url rewriter... Mahana would keep it all part of the web
app and use a filter, methods differ but the effect is the same.

Default Redirect using Struts2

Currently when you hit the root context of my application Struts2 throws an error:
ex. http://localhost:8080/
returns
HTTP ERROR 404
Problem accessing /. Reason:
There is no Action mapped for namespace / and action name .
Is there a way to do a default redirect in Struts2?
In my app I just do the following to redirect to a chosen action:
<action name="*">
<result type="redirectAction">
<param name="actionName">portal</param>
</result>
</action>
Just make sure you place this as the last action in your struts.xml configuration file and then it will catch everything that couldn't be matched earlier on.
This way the redirect happens within struts2, this is invisible to the user.
You can specify a welcome-file-list in web.xml and specify index.jsp, for example:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Then in index.jsp, you can put this at the top:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=initLogin.action">
Assuming you have something like this in struts.xml:
<action name="*Login" method="{1}" class="com.abc.LoginAction">
<result name="login">/login.jsp</result>
<result name="register">/register.jsp</result>
<result name="success">/success.jsp</result>
</action>
This will redirect to your LoginAction class with an init action.
So then if I went to http://localhost:8080/MyApp, this is the default action it would go to.
Is there no better thing than the meta refresh? Such as in struts there was a jsp:forward... that seems to not work in struts2. I don't know how much I am comfortable with the meta refresh. And don't know different it is than using any java provided redirect, guess I could use that dispatcher class which maybe in the jsp, not sure though.
Go through the examples in the following link, lot of tutorials are given there, using which you can identify your mistakes..
link, link2

Resources