小编Lee*_*ald的帖子

JSF 2.1和IE条件评论

我注意到在JSF 2.1中.*我的IE条件注释不再有效.HTML实体正在替换各种字符并使注释语法无效.BalusC 在另一个使用h:outputText 的问题中指出了问题的解决方案.我的问题是我希望我的条件评论位于我的页面顶部,围绕第一个元素.这意味着我不能使用h:outputText,因为我还没有定义它的命名空间.无论如何,我相信这是正确的.这是一个代码示例.

现在大多数JSF页面都会以类似于HTML5 Boilerplate语法的模板开始:

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7 my-application" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8 my-application" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9 my-application" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js my-application" xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" lang="en"><!--<![endif]-->
<h:head>
  <meta charset="utf-8" />
  ...
Run Code Online (Sandbox Code Playgroud)

有了BalusC提到的解决方案,我想<h:outputText />在第2行但是h命名空间还没有定义.这是我可以使用的元素,我可以附加各种命名空间但不会影响我的最终HTML吗?我有什么其他想法可以解决这个问题吗?

李,

jsf conditional-comments jsf-2

5
推荐指数
1
解决办法
3016
查看次数

枚举和构建器模式的通用类型

我正在尝试创建一个构建器模式,该模式使用泛型来提供某些方法的类型检查.目前我有以下工作:

ParameterBuilder.start(String.class).setName("foo").setDefaultValue("Hello").build();
ParameterBuilder.start(Integer.class).setName(bar).setDefaultValue(42).build();
ParameterBuilder.start(Boolean.class).setName(bar).setDefaultValue(false).build();
Run Code Online (Sandbox Code Playgroud)

使用代码:

public class ParameterBuilder<T> {
  private String name;
  private T defaultValue;

  public static <T2> ParameterBuilder<T2> start(Class<T2> type) {
    return new ParameterBuilder<T2>();
  }
  // Other methods excluded for example
}
Run Code Online (Sandbox Code Playgroud)

因此,setDefaultValue方法的输入类型由传递给方法的内容定义start,就像我想要的那样.

但现在我想扩展传递的内容start()以包含更多信息.基本上我想为我创建的参数传递一个"类型".有时这些参数将是"email","url"等.默认值仍然是已知类型(在这种情况下为String),所以我希望有类似的东西:

ParameterBuilder.start(EMAIL).setName("email").setDefaultValue("foo@bar.com").build();
ParameterBuilder.start(URL).setName("website").setDefaultValue("http://www.somewhere.com").build();
Run Code Online (Sandbox Code Playgroud)

目前,EMAIL和URL是枚举,包含其他内容 - 默认值的类.但是,如果我沿着这条路走下去,我将如何实例化参数构建器?

public static <T2> ParameterBuilder<T2> start(ParameterType paramType) {
  Class<T2> type = paramType.getTypeClass();
  // How do I instantiate my ParameterBuilder with the right type?
}
Run Code Online (Sandbox Code Playgroud)

如果使用枚举无法完成(我可以看到这种情况),是否有人建议使用其他解决方案?

java generics type-erasure

5
推荐指数
1
解决办法
1265
查看次数

空白xmlns =""导入的属性

我正在尝试对XML文档进行转换.我的XML转换可以导致两种不同类型的基本元素,具体取决于某个元素的值:

<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="/databean/data[@id='pkhfeed']/value/text()='200'">
      <xsl:call-template name="StructureA">
        <xsl:with-param name="structure" select="//databean" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="StructureB">
        <xsl:with-param name="structure" select="//databean" />
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

然后使用自己的名称空间和schemaLocations创建StructureA或StructureB:

<StructureA xmlns="http://...">
Run Code Online (Sandbox Code Playgroud)

StructureA&B共享一些共同元素,因此这些元素在一个名为"xmlcommon.xslt"的单独文件中定义,两个结构都包含来自的模板.此xmlcommon文件没有定义默认命名空间,因为我希望它可以从StructureA或StructureB中定义的命名空间中使用.但是当我运行我的转换时,从公共文件中引入的任何模板都会产生空白的xmlns属性:

<StructureA xmlns="http://...">
  <SharedElement xmlns="">Something</SharedElement>
</StructureA>
Run Code Online (Sandbox Code Playgroud)

验证时,然后使用空白名称空间而不是正确的父名称空间. 有谁知道如何阻止我的公共文件中的模板添加那些空白的xmlns属性?

这是公共文件的片段:

<xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template name="ControlledListStructure">
    <xsl:param name="xmlElem" />
    <xsl:param name="structure" />

    <xsl:element name="{$xmlElem}">
      <!-- Blah blah blah -->
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

xml xslt xml-namespaces

4
推荐指数
1
解决办法
4379
查看次数

使用JSF,MyFaces和Facelets迭代HashMap的麻烦

我在循环HashMap以将其值打印到屏幕上时遇到了一些麻烦.有人可以仔细检查我的代码,看看我做错了什么.我似乎找不到任何错误,但必须有一些东西.

在servlet中,我将以下内容添加到请求中:

Map<String, String> facetValues = new HashMap<String, String>();
// Filling the map
req.setAttribute(facetField.getName(), facetValues);
Run Code Online (Sandbox Code Playgroud)

在一种情况下,"facetField.getName()"评估为"纪律".所以在我的页面中我有以下内容:

<ui:repeat value="${requestScope.discipline}" var="item">
  <li>Item: <c:out value="${item}"/>, Key: <c:out value="${item.key}"/>, Value: <c:out value="${item.item}"/></li>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)

循环运行一次,但所有输出都是空白的?!?如果它已经超过循环一次,我至少会期望项目中的某些东西.检查Facelets的调试弹出窗口,纪律是在那里和循环.将它打印到屏幕会产生一些看起来像我的地图(我缩短了输出):

{300=0, 1600=0, 200=0, ... , 2200=0}
Run Code Online (Sandbox Code Playgroud)

我也尝试过ac:forEach,但我得到了相同的结果.所以有人有任何想法,我出错了吗?

谢谢你的任何意见,李

java jsf facelets myfaces

3
推荐指数
2
解决办法
1万
查看次数

Thymeleaf:URL中的参数未被替换

我正在努力学习Spring MVC和Thymeleaf.我有以下HTML部分打印出一个链接和一个按钮:

<ul th:each="item : ${typesMap}">
  <li>
    <a href="roomdetails.html" th:href="@{/roomdetails/${item.key}/${item.value}}">Linky</a>
    <button type="button" th:text="${item.value}">Button Text</button>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

在这两个示例中,链接中的参数永远不会被替换.我总是最终roomdetails/${item.key}/${item.value}得到HTML中的一些东西.该按钮工作正常,并将显示在循环的每次迭代中在$ {item.value}中找到的文本.

有谁知道为什么我不能以我想要的格式获取URL?从我所看到的,我正在做文档告诉我的内容.

java spring-mvc thymeleaf

2
推荐指数
1
解决办法
4653
查看次数