I'm trying to create a menu template in JSF where the link for the current directory has a different "current" or "active" class. The code currently looks like:
<ul>
<li><h:outputLink value="#{request.contextPath}/a/">A</h:outputLink></li>
<li><h:outputLink value="#{request.contextPath}/b/">B</h:outputLink></li>
<li><h:outputLink value="#{request.contextPath}/c/">C</h:outputLink></li>
</ul>
I'm thinking of using something like styleClass="#{(thisDir == currentDir) ? currentLinkClass : normalLinkClass}". But how do I get the current path? Is this even correct, or is there a better way to do this?
Also, I want the links to base on the current path, not just the page. For example, myapp/a/1.jsf and myapp/a/2.jsf (that is, myapp/a/*.jsf) should trigger the active class for the A link. (I hope my explanation is clear.) Is this possible? How should this be done?
Thank you very much!
You can use #{request.requestURI} to get the current request URI. You can if necessary use several EL functions from JSTL fn taglib to do some string comparisons/manipulations in EL.
Your proposed EL styleClass suggestion is perfectly fine. There is no other easy way anyway. Best optimization which you could do so far is to render those links in a loop by an <ui:repeat> so that code duplication is at least eliminated.
You can also try this approach which uses #{view.viewId}:
<h:outputLink
styleClass="#{(view.viewId.equals('/admin/authors.xhtml')) ? 'active' : 'inactive'}"
value="authors.xhtml">Text</h:outputLink>
Related
In Liferay 6.1, we created a hook to hide the sign out link in the dockbar. However, when I look at the code for 6.2, I see the following:
<c:if test="<%= themeDisplay.isShowSignOutIcon() %>">
<aui:nav-item cssClass="sign-out" href="<%= themeDisplay.getURLSignOut() %>" iconCssClass="icon-off" label="sign-out" />
</c:if>
No matter how much I google, I can't find any reference to themeDisplay.isShowSignOutIcon(), aside from the API reference, which does me no good, as it is not commented at all. I did find the page that discusses the native LR theme properties and apparently determining whether to show/hide a sign out linkn is not one of the native theme properties.
Does anyone know if you can set the theme itself to show/hide the sign out link and how you would go about doing it?
I too analyzed ServicePreAction code, and found that all this code does is:
checks if the user is logged in or not
if yes, shows 'sign out' link, not otherwise
You can simply create a hook to override html/portlet/dockbar/view_user_account.jspf to either remove that code snippet from this jsp to hide it for all scenarios OR modify the condition to show/hide as per your requirements.
The only place that I've found where ThemeDisplay.setShowSignOutIcon is called is in ServicePreAction (linking master branch here). That being said, it looks like it's not configurable, but you can easily create another ServicePreAction in a hook. Please see an example in this plugin (referencing portal.properties and liferay-hook.xml, but naturally there's also code that I'm sure you'll find. It's not big)
Another option - if you just want to unconditionally get rid of the link: Use CSS to hide it. Yes, it will still be there, but any way you choose to hide the link, the actopm at /c/portal/logout will still be available...
I'm trying to create some scripts which require moving through a lot of on-the-fly HTML with random IDs. They require getting the parents of an element - but I'm not sure how to implement this in WebdriverJS.
If I access the element I want via a console, I can do the following to get it;
document.querySelector('span[email="noreply#example.com"]').parentNode.parentNode
Is there a way to do this in WDJS? I've looked and can't see anything obvious - it's specifically the parent stuff I'm having issue with. I saw that a possible solution may be xPath however I'm unsure of syntax having never used it before.
Thanks in advance!
I don't know the syntax of WebDriverJS. But the XPath is as below, you need a way to fit it in somewhere.
This is based on your CSS Selector, so please show HTML if needed.
.//span[#email='noreply#example.com']/../..
For example, if you have HTML like this
<div>
<div>
<span email="noreply#example.com">Contact me</span>
</div>
</div>
You can avoid using .. to go up.
.//div[./div/span[#email='noreply#example.com']]
If you have more levels to look up, another handy method would be using ancestor from XPath Axes.
Also, as #sircapsalot brought up, CSS selectors spec doesn't support parent selecting, so XPath is the only way to go, unless you inject JS.
in the upper left corner of my app there is a logo. After I click on it I would like to be redirecterd to home page wherever I am now.
Of course I could just link it www.myhomepage.com but that is not very nice and scalable.
I could link it to action="../spring/main-flow" but that is not good either.
How should I do this properly?
Thanks in advance
Link to the context path directly:
...
Or when you're still using old fashioned JSP as view technology:
...
Works also in combination with <h:outputLink>.
Or use the new JSF2 <h:link>, if you have for example a index.xhtml, it will prepend the context path automatically:
<h:link outcome="/index">...</h:link>
Anything other than / seems overly complicated, unless different sub domains are involved.
I am building a website with ExpressionEngine as the CMS. There is a "Work" section that displays all the projects, and a detail view that shows each project individually. It is at this point, on the single-entry view that I would like to have "prev" and "next" pagination. In my tests I have made it work when the URL is "somedomain.com/index.php/work/detail/" but it does not work when the specific entry is part of the URL: "somedomain.com/index.php/work/detail/some_project/"
I've tried putting the pagination code outside of the {exp:weblog:entries} tag as well as within it, but to no avail. This is what my pagination code looks like:
{paginate}
<ul>
{if previous_page}
<li>< previous</li>
{/if}
{if next_page}
<li>next ></li>
{/if}
</ul>
{/paginate}
You are using pagination for lists of entries, what you need is the next / previous entry tags:
http://expressionengine.com/user_guide/modules/channel/entry_linking.html
Hmm. I'm not sure what the issue is here, as I've never used the {pagination} tag in that way. After checking out the docs, I see that the example code for prev/next links inside of the {pagination} tag is wrapped inside of an {exp:comment:entries} loop instead of the normal {exp:channel:entries} loop.
The docs aren't very clear about the scope of this particular feature of the {pagination} tag. You might want to double check that, in your {exp:channel:entries} loop, you haven't included pagination as a value in the disable parameter.
You could also check out the page in EE's user guide about Next/Prev Linking, which details the use of {exp:channel:next_entry} and {exp:channel:prev_entry} tags in place of the {pagination} tag that you've been using. I've used these tags without a hitch, so I definitely recommend trying them if you can't get your method to work.
Best of luck!
How is it possible to enclose ajax-related elements with h:form tags in a jsp file which I want to then a4j:include in another jsp file given the suggestion (EDIT 3) to fix another problem by enclosing my a4j:include in an h:form tag?
If my included code also has forms in that would suggest a nested form structure which will likely cause problems. A solution to how to go about this would be greatly appreciated.
I'm creating a webapp which uses ajax components so there is no page to page navigation as such as I want everything in the same 'window'.
Thanks
You may use <a4j:region> instead of <x:form>. Nesting form is not recommended indeed.