XSLT,JSTL和JSF [英] XSLT, JSTL e JSF

查看:77
本文介绍了XSLT,JSTL和JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要在jsf代码页中转换的xml文件.为此,我创建了一个xsl文件.

I have a xml file which I want to transform in a jsf code page. To do that I've created a xsl file.

xml:

<?xml version='1.0' encoding='ISO-8859-1'?>
<questionario xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
              xsi:noNamespaceSchemaLocation='Schema2.xsd'>
    <componente nome='input'>
         <id>input1</id>
    </componente>
    <componente nome='input'>
         <id>input2</id>
    </componente>
</questionario>

代码:

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>

<c:set var="xml" value="${questionarioXSLBean.xml}"/>

<c:set var="xsl">
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    exclude-result-prefixes="f h">

    <xsl:template match="/">
  <xsl:for-each select="questionario/componente">
   <xsl:if test="attribute::nome = 'input'">
    <xsl:variable name="id">
     <xsl:value-of select="id" />
    </xsl:variable>
    <h:inputText id="{$id}"/>
   </xsl:if>
  </xsl:for-each>

 </xsl:template>

</xsl:stylesheet>
</c:set>

<x:transform xml="${xml}" xslt="${xsl}" />

问题是我的屏幕上什么都没有显示,因为<h:inputText id="input1"/>的生成代码是<h:inputText id="input_1" xmlns:h="http://java.sun.com/jsf/html"/>,我该如何替换xmlns:h ="http://java.sun.com/jsf/html"或压制它.

The problem is that nothing is shown in my screen because the generated code for <h:inputText id="input1"/> is <h:inputText id="input_1" xmlns:h="http://java.sun.com/jsf/html"/> how can I replace the xmlns:h="http://java.sun.com/jsf/html" or suppress it.

谢谢!

更新:让我澄清一下我想做什么.我想根据xml文件的属性动态生成jsf页面,例如2个输入文本,3个复选框等.要转换为jsf,我想了两种方法,一种使用jstl,另一种使用xslt.前者的问题是我无法将jstl与jsf代码集成(使用jstl变量设置jsf组件属性),而在最后一种方法中,我遇到了上述问题. java(UIComponents).有什么建议?

Update: Let me clarify what I want to do. I want to generate a jsf page dynamically depending on the attributes of a xml file, for instance, 2 input texts, 3 check boxes, etc. To make the transformation to jsf I thought in two approaches, one using jstl and another using xslt. The problem with the former is that I couldn't integrate jstl with jsf code (to set jsf components attributes using jstl variables) and with the last approach, I'm facing the problem described above.I wouldn't like to create components in java (UIComponents). Any suggestions?

推荐答案

我从来没有像现在这样做过,但是从理论上讲,当您在生成的XHTML输出中看到未解析的JSF标记时,则仅表示尚未完成工作.您需要确保它已在指定的url-patternweb.xml中注册,并且请求URL(如在浏览器地址栏中)与FacesServleturl-pattern相匹配.如果是例如*.jsf,则不应通过 http://example.com打开JSP页面/page.jsp ,但 http://example.com/page.jsf .

I've never done it like this, but in theory, when you see JSF tags unparsed in the resulting XHTML output, then it simply means that the FacesServlet hasn't done its job. You need to ensure that it is registered in web.xml on a specified url-pattern and that the request URL (as in browser address bar) matches the url-pattern of the FacesServlet. If it is for example *.jsf, then you shouldn't open the JSP page by http://example.com/page.jsp but by http://example.com/page.jsf.

更新:正如我所说,我从来没有那样做过,我怀疑它在理论上是否会奏效.但是,根据经验,我可以说出

Update: as said, I've never done like that and I doubt if it will ever work in theory. However, from experience I can tell that the approach as described in this answer works. The XSL should have done its job before the view is been passed through the FacesServlet. Right now you're trying to do it simultaneously.

这篇关于XSLT,JSTL和JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆