How to define displaytag.tld offline? - struts2

I want to define my displaytag.tld offline so that my application will no longer need to access uri="http://displaytag.sf.net", i put
<%# taglib prefix="display" uri="/displaytag"%>
in my jsp but it has error, i put my displaytag-1.2.jar inside /WebContent/WEB-INF/lib/. Can anyone advise me what to do next in order to eliminate the error? I'm using Eclipse IDE.
Thanks in advance.

uri="http://displaytag.sf.net" Look like a URL to a web resource.but it is not. it just a name that happens to be formatted as a URL. so instance of
<%# taglib prefix="display" uri="/displaytag"%> use
<%# taglib prefix="display" uri="http://displaytag.sf.net"%>
you can see tld file in inside META-INF folder of your jar file.

Related

sitemesh + struts2 How to include external files in standard.jsp

My company has 20+ web applications. They all use Struts2 and Sitemesh to decorate the pages.
Every application has its own version of header.html and footer.html which are included in standard.jsp (using <%# include file=filename%>).
For look and feel consistency across applications I want to have the header and footer files outside of the web application.
However I can't figure out how to do that!
My decorator.xml looks like this
<decorators defaultdir="/layout">
<decorator name="standard-layout" page="standard.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
My include directive <%# include file="/common/header.html%>, gets prefix with the defaultdir value, like this /layout/common/header.html, and I get a file not found error.
The same thing happens if I use an absolute path.
Also, the same thing happens if I change decorators.xml like this.
<decorators>
<decorator name="standard-layout" page="/layout/standard.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
Help will be appreciated!
Update: I was able to solve this using JSTL
<c:import var="commomHeader" url="/resources/html/common_header.html"/>
${commomHeader}

grails app root context

I have a test grails app setup with a context of "/testapp". When I add a link in my gsp that references / it does not go to the root of my grails.app.context, but to the root of my grails.serverURL property.
For example given a link with href "/css/main.css"
I would expect that this link would actually look in localhost:8080/testapp/css/main.css instead of localhost:8080/css/main.css
Is there a way that I can get references to / to start at my grails.app.context vs the grails.serverURL?
use the request contextPath value on the page
${request.contextPath}
and then prepend the additional host information if necessary to construct the complete url
the question is how do you add your links into your gsps?
We do things like
<link rel="stylesheet" href="${resource(dir: 'css', file: 'stylesheet1.css')}"/>
and
<g:javascript library="prototype"/>
by using the g:javascript and resource tags and methods, you tell grails to set the path for you...
I suspect you are just putting standard tags in...
goto
http://grails.org/doc/latest/
and, under tags in the left hand nav, look for resource and/or javascript to get an idea (its difficult to link directly in to the docs...:()
I had a similar issue to OP - how to have grails form links that start at the context root and NOT server root?
You can do so using the "uri" attribute for g:link and g:createLink tags. For example:
<g:link uri="/login">login</g:link>
will prefix any context if applicable, and produce the following
login if your app is at the http://server/
login if your app is at http://server/testapp/
Not sure why it's an undocumented attribute in the reference docs, but I found it in the Javadocs - ApplicationTagLib
You should probably be using the resource tag into your grails CSS directory, like mentioned above. However, you can also use the resource method to find the root context of you web application using the same tag:
${resource(uri:'/')}
then just use that string wherever.
And when it comes to elements like stylesheets I'd recommend creating a simple tag that'll do the trick, something along those lines:
class StylesTagLib {
static namespace = "g"
def stylesheet = { args, body ->
out << """<link rel="stylesheet" href="${resource(dir: 'css', file: args.href)}"/>"""
}
}
and later on in your code use it like this:
<g:stylesheet href="main.css"/>
Obviously you can fiddle with the conventions (should I use a predefined folder? should I add the .css extension automatically? stuff like that) but the general idea is to hide the ugliness behind a nicely defined tag.

In MVC view page javascript file url not resolving

I have one MVC view page in which I show different links and I am using ThickBox to show a different page when ever one of these links is clicked. In these pages, I am using jQuery functions to do some changes, but I am not able to resolve the jquery file path on the view pages. I need to give absolute path something like "http://test.com/js/jquery.js". But is there any way to make it relative?
I also tried getting the host url and using <%=%> and <%# %> but none is working.
Any help?
Thanks
Ashwani
This is when you run the MVC app from visual studio? If so set you're MVC application's virtual path to start at "/" instead of the default that is probably your project name.
This can be done by right-clicking on the MVC project in the solution explorer > Click Properties > Click the Web tab > Type "/" (without the quotes) in the Virtual path textbox. Then use Andrew Florko's suggestion of leading it with a slash <script src="/js/jquery.js"> </script>
alt text http://img707.imageshack.us/img707/3765/virtualpath.jpg
What about trying something like:
<script src="<%=Url.Content("~/js/jquery.js")%>" type="text/javascript"></script>
Maybe you should try
<script src="/js/jquery.js" ...
instead of intellisence-generated path with ".."
<script src="../../js/jquery.js" ...

ASP.NET MVC Ambiguous type error - 'System.Web.Mvc.ViewMasterPage' is ambiguous

I created an ASP.NET MVC 2.0 Application. It ran fine at first test and I made some minor edits to the views. I then wanted to add a new controller so I had to compile the app. After I did anytime I run it I get the following error:
Parser Error Message: The type 'System.Web.Mvc.ViewMasterPage' is ambiguous: it could come from assembly 'C:\Users\DerekM\Documents\Visual Studio 2008\Projects\ABELMedicalSoftwareMVC\ABELMedicalSoftwareMVC\bin\System.Web.Mvc.DLL' or from assembly 'C:\Users\DerekM\Documents\Visual Studio 2008\Projects\ABELMedicalSoftwareMVC\ABELMedicalSoftwareMVC\bin\ABELMedicalSoftwareMVC.DLL'. Please specify the assembly explicitly in the type name.
Source Error:
Line 1: <%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
I did some googling and came accross the following tutorial: http://blog.stevensanderson.com/2009/02/03/using-the-aspnet-mvc-source-code-to-debug-your-app/
I followed it exactly but I still get the same error. So I have the System.Web.Mvc.dll reading from my bin folder now, and the reference to the GAC was removed from my web.config.
From what I can gather from other posts it sounds like my inherits on my view pages, or maybe my master pages, is the issue. But I'm not sure how to edit them.
Here is the inherits from the default Site.Master MVC created
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
And here is the inherits from my view
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
Forum posts im reading say it needs to reference the code behind instead, but the views have no code behind in them. It's just a plain Index.aspx file.
The default master page has no code behind, but if I create a new one it gets given a .cs and .designer.cs
Any help appreciated, this seems like such a simple issue and I'm missing something really basic.
I think you have codebehind for this masterpage.
Change the inherit from
System.Web.Mvc.ViewMasterPage instead
of System.Web.UI.MasterPage.
I had the same issue, and this had helped me: http://www.alphapapahotel.com/system-web-mvc-viewmasterpage-parser-erro/aspnet/

Avoid "The class or CssClass value is not defined" Warnings in ASP.NET MVC ASCX Partial Views (UserControls)

I wondered how I can stop those annoying compiler warnings "The class or CssClass value is not defined" coming from my ASP.NET MVC partial views/ASCX user controls. The CSS is correctly defined, but the reference to the CSS file is obviously on the master page only. My partial views contain lots of CSS class references on div's etc. and so I get massive amounts of warnings which I shouldn't see.
How can I solve this?
Thank you !
Include this in your partial view:
<% if (false) { %>
<link rel="stylesheet" type="text/css" ...
<% } %>
This will make intellisense happy, and excludes the stylesheet when the page is rendered, so that it is not included twice.
One way is to turn HTML Syntax Checking off (Tools->Options->Text editor->HTML->Show Errors->In CSS).
I use the Firefox Tidy plug in, which gives better advice, IMHO.
This is not a flaw in ASP.Net MVC, and I don't think it's going to be it's going to be fixed in the next version. This is a 'limitation' (notice how i avoid the word flaw) in asp.net (not just mvc) that prevents it from accessing header information that's included in the master page. So you don't have access to javascript/css in the content pages/usercontrols.
The code provided by Robert Harvey is a hack solution that we've been using to overcome this.
It works by using the enclosing the include file in an if block that's always false. So the compiler sees the css file but the runtime doesn't.

Resources