我正在研究自定义标记库,我很困惑如何在TLD文件中使用<required>和<rtexprvalue>标记来定义自定义标记属性.
我目前正在开发基于Spring 3.1.0.M1的基于注释的Web应用程序,并且我在应用程序的一个特定位置解析属性占位符时遇到问题.
这是故事.
1)在我的Web应用程序上下文(由DispatcherServlet加载)中,我有
MVC-config.xml文件:
<!-- Handles HTTP GET requests for /resources/version/** -->
<resources mapping="/${app.resources.path}/**" location="/static/" cache-period="31556926"/>
...
<!-- Web properties -->
<context:property-placeholder location="
classpath:app.properties
"/>
Run Code Online (Sandbox Code Playgroud)
2)在app.properties内部,有2个属性,其中包括:
app.properties:
# Properties provided (filtered) by Maven itself
app.version: 0.1-SNAPSHOT
...
# Static resources mapping
app.resources.path: resources/${app.version}
Run Code Online (Sandbox Code Playgroud)
3)我在JSP 2.1模板中有一个JSP自定义标记.此标记负责完整的资源路径构建,具体取决于环境设置,应用程序版本,弹簧主题选择等.自定义标记类扩展spring:url实现类,因此它可能被视为通常的url标记,但具有关于正确路径的一些额外知识.
我的问题是我无法在JSP自定义标记实现中正确解析$ {app.resources.path}.JSP自定义标记由servlet容器管理,而不是Spring,因此不参与DI.所以我不能只使用通常的@Value("$ {app.resources.path}")并由Spring自动解决它.
我所有的都是Web应用程序上下文实例,所以我必须以编程方式解析我的属性.
到目前为止我试过:
ResourceTag.java:
// returns null
PropertyResolver resolver = getRequestContext().getWebApplicationContext().getBean(PropertyResolver.class);
resolver.getProperty("app.resources.path");
// returns null, its the same web context instance (as expected)
PropertyResolver resolver2 = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext()).getBean(PropertyResolver.class);
resolver2.getProperty("app.resources.path");
// throws NPE, resolver3 …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建按钮ala Wufoo(重新发现按钮元素)
我想写下面的代码如下:
<%form_tag search_path, :method => :get, :class => 'search' do %>
<%=text_field_tag :search, params[:search] -%>
<%=button_tag 'search', :name => nil-%>
<%end%>
Run Code Online (Sandbox Code Playgroud)
生成以下HTML(而不是输入[type ="submit"]标记)
<button type="submit" class="positive">
<img src="/images/icons/tick.png" alt=""/>
Save
</button>
Run Code Online (Sandbox Code Playgroud)
方法是否已存在?或者我应该自己动手帮忙?
我找到了一个网站,其中包含向html添加自定义标签的指南,与人们制作的方式相同,即使用新的HTML5标签.我必须承认,我认为添加自己的标签会更好,可以更容易"扫描"代码,并找到您要查找的内容.但是我找到的每个网站都有人说这不好......但为什么不好呢?
示例html与类:
<ul class="commentlist">
<li class="comment odd">
<div class="1">
<div class="avatar">
<img src="http://placehold.it/60x60" width="60" height="60" />
</div>
<div class="metadata">
<div class="name">Name</div>
<p>response1</p>
</div>
</div>
<ul class="children">
<li class="comment even">
<div class="2">
<div class="avatar">
<img src="http://placehold.it/60x60" width="60" height="60" />
</div>
<div class="metadata">
<div class="name">Name</div>
<p>response1a</p>
</div>
</div>
</li>
<li class="comment odd">
<div class="3">
<div class="avatar">
<img src="http://placehold.it/60x60" width="60" height="60" />
</div>
<div class="metadata">
<div class="name">Name</div>
<p>response1b</p>
</div>
</div>
</li>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
在这里我可以用自定义标签做什么,我认为找到自己的方式会更容易,所以为什么不呢:
<clist>
<ccommentbox class="odd">
<ccomment class="1">
<cavatar>
<img src="http://placehold.it/60x60" width="60" …Run Code Online (Sandbox Code Playgroud) 嗨,我刚刚创建了在我的JSP中使用的自定义标记.标签的.tld是这样的
<?xml version="1.0" encoding="UTF-8"?>
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>acma</shortname>
<info>AccountManag</info>
<tag>
<name>clookup</name>
<tagclass>taglib.acm</tagclass>
<info>Customer Lookup</info>
<attribute>
<name>cust_id</name>
<required>true</required>
</attribute>
</tag>
</taglib>
Run Code Online (Sandbox Code Playgroud)
现在标签工作得很好,当我使用int值时,如此cust_id ="1"
<dd:clookup cust_id="1"></dd:clookup>
Run Code Online (Sandbox Code Playgroud)
但是当我使用EL时,它不起作用
<dd:clookup cust_id="${sessionScope.cust.id}"></dd:clookup>
Run Code Online (Sandbox Code Playgroud)
所有教程都以int或其他数据类型开头,所以我无法找到任何可能有用的资源..任何建议?
我正在使用Visual Studio 2013来创建原始HTML页面(即index.html).
在我的HTML中,我正在实现自定义HTML标记.因此,Visual Studio使用波浪线强调我的自定义标记(由于"未知元素..."的警告).
为了摆脱波浪形,我将自定义标签添加到"标签特定选项"列表中Tools > Options > Text Editor > HTML (Web Forms) > Formatting > Tag Specific Options.然而,波浪线仍然存在.
有没有办法通知VS2013我的自定义HTML标签是有效的(即保持VS2013不要用波浪线强调我的自定义标签)?
我想用一些语义[X] HTML标签,而不是<div>S: ,,<article> 等他们有的在即将到来的HTML5已经提出,但是,它不完全支持.<product><footer>
渲染时我可能面临哪些可能的缺点?使用CSS,JS?
我记得的是:IE6无法克隆它不知道的标签.
我正在尝试实现一个自定义JSP标记,它接受作为Collection对象的属性a 并将它们输出为JSON格式的数组(Collection提供一个getJsonString()返回该对象的JSON格式表示的方法中的每个对象).我的标签实现如下:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ attribute name="objects" required="true" rtexprvalue="true" %>
<c:set var="output" value="" />
<c:forEach var="obj" items="${objects}">
<c:if test="${! empty showComma}">
<c:set var="output" value="${output}, " />
</c:if>
<c:set var="output" value="${output}${obj.jsonString}" />
<c:set var="showComma" value="yes" />
</c:forEach>
[${output}]
Run Code Online (Sandbox Code Playgroud)
...我想通过做类似的事情来使用它:
<myTaglib:jsonArray objects="${myCollection}" />
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用标记时,我得到一个堆栈跟踪说:
javax.el.PropertyNotFoundException: Property 'jsonString' not found on type java.lang.String
Run Code Online (Sandbox Code Playgroud)
所以它抱怨${obj.jsonString}表达,但我绝对不会传递一些Collection字符串.此外,如果我将其更改为${obj}我看到正在输出的正确对象类型,并且如果我将自定义标记的代码复制/粘贴到我想要使用它的JSP中,它可以正常工作,所以我真的不确定是什么继续在这里.
我假设我将如何传递Collection到自定义标签有一些问题,但我无法弄清楚它是什么.有任何想法吗?
我编写了一个自定义 Javadoc taglet,它添加了一个新note标签:
...
public boolean isInlineTag() { return false; }
public String toString(Tag tag) {
return "<pre class='note'>" + tag.text() + "</pre>";
}
Run Code Online (Sandbox Code Playgroud)
到目前为止它可以工作,但是内联标签没有扩展。这是一个评论示例:
/**
* @note Test note with {@link Someclass} // @link tag is NOT expanded
* @param name - here the {@link Someclass} works // works for standard 'param' tag
*/
Run Code Online (Sandbox Code Playgroud)
内联标签{@link}未展开。但是,它对于内置paramjavadoc 标记来说效果很好。
有没有办法在自定义 Javadoc taglet 中扩展嵌套内联标签?
谢谢!
我想知道我是否可以为我的网站创建一个自定义HTML标签,其功能与Facebook的Open Graph元标签相同.
我在考虑这样的事情:
<mysite title="My website title" description="Some description"
image="http://mysite.com/image.png">
Run Code Online (Sandbox Code Playgroud)
然后使用PHP获取此数据(我已经可以使用meta-tags执行此操作).
一些要点:
我使用HTML5,使用这种方法有什么语法问题吗?
Google+使用类似这样的内容:g:plusone