请原谅我的头衔,这是我最近有限的大脑最好能够提出的.
所以,我有一个字符串列表,如[abc,def,ghi].
问题:在JSF中,我如何迭代列表并创建一个看起来像这个"abc,def,ghi"的字符串(注意逗号)?
对于那些有冲动告诉我我最好使用Java方法来连接字符串的人,请听一下:列表中的每个成员都应该作为单独的commandLink呈现.
如果普通的JSF看起来像:
<h:commandLink>abc</h:commandLink>, <h:commandLink>def</h:commandLink>, <h:commandLink>ghi</h:commandLink>
Run Code Online (Sandbox Code Playgroud) 我目前正在使用JSF 2.0中的facelets进行实验.
我目前有一个案例,其中2个facelets使用公共网格定义,仅在bean名称,列表名称,标题,网格id等某些区域有所不同.
所以我的想法是:
<ui:insert>在使用它的页面之间可能不同的区域<ui:define>这是我的gridTemplate.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
<title>#{msgs.title}</title>
</h:head>
<h:body>
<ui:composition template="/template/masterlayout.xhtml">
<p:dataTable id="<ui:insert name='gridId' />" var="rpb"
value="#{<ui:insert name='bean' />.<ui:insert name='list' />}">
<f:facet name="header">
<h3><ui:insert name='title' /></h3>
</f:facet>
.....
<f:facet name="footer">
#{fn:length(<ui:insert name='bean' />.<ui:insert name='list' />)} records<br />
</f:facet>
</p:dataTable>
</ui:composition>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是使用网格模板的facelet之一:
<ui:composition template="gridTemplate.xhtml">
<ui:define name="gridId">grid</ui:define>
<ui:define name="bean">myBean</ui:define>
<ui:define name="list">myList</ui:define>
<ui:define name="title">my message !</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
这个实验最终得到: …
在我使用JSF的Web应用程序中,某些验证器(例如长度验证器<f:validateLength></f:validateLength>,正则表达式验证器)<f:validateRegex></f:validateRegex>和其他一些验证器在加载JSF页面时即使工作正常也没有问题,也会发出一些错误,甚至可能是警告。
这里不需要JSF ManagedBean,并且以下代码中显示的Submit按钮与之无关,因为Ajax在给定文本字段的valueChange事件上触发。
以下是简单的JSF页面代码。
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Demo</title>
</h:head>
<h:body>
<h:form>
<center><br/><br/><br/>
<h:inputText id="txtDemo" required="true" requiredMessage="Mandatory."
validatorMessage="The field should contain al least 10 digits">
<f:validateLength id="lenValidator" for="txtDemo" maximum="10"
minimum="2"/>
<f:validateRegex pattern="[0-9]*" for="txtDemo" id="txtPattern"/>
<f:ajax id="txtAjax" event="valueChange" execute="txtDemo msg"
render="txtDemo msg"/>
</h:inputText><br/>
<h:message id="msg" for="txtDemo" showDetail="true" style="color:red"/>
<br/>
<h:commandButton id="btnSubmit" value="Submit"/>
</center>
</h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,尽管验证器<f:validateLength></f:validateLength>和<f:validateRegex></f:validateRegex>可以正常工作,但是长度验证器不允许少于2个字符和大于10个字符,并且正则表达式验证器确保该字段应仅包含数字,当出现以下情况时,控制台上会出现红色消息:此JSF页面已加载。显示的消息如下。
SEVERE: /Restricted/TempTags.xhtml @12,93 id="lenValidator" Unhandled by MetaTagHandler for type javax.faces.validator.LengthValidator
SEVERE: …Run Code Online (Sandbox Code Playgroud) 当我通过Glassfish服务器访问嵌入了applet的Facelets页面时,我收到此错误.虽然当我只是从我的电脑打开它时,它工作正常,所以小程序是好的.是否可以在Glassfish(3.1,JSF 2.0)上运行applet?
这是我尝试的方式:
<applet code="test.TestApplet" archive="TestApplet.jar"/>
Run Code Online (Sandbox Code Playgroud) 我是JSF的新手,我正在构建一个使用facelets创建的应用程序.
这是我的模板
master.xhtml
<body id="body">
<form id="frmmaster">
<div id="pg-nav-bg">
<div class="wrapper clear">
<div class="footer clear">
<div class="footerContent">Help Des</div>
</div>
<div id="pg-nav">
<ul class="nav sf-js-enabled">
<li class="page_item" id="liHomr">
<a href="#" title="Home">Home</a>
</li>
<li class="page_item" id="liFreeSearch">
<a href="#" title="Free Search" >Free Search</a>
</li>
<li class="page_item" id="liMasterSearch">
<a href="#" title="Search">Search</a>
</li>
<li class="page_item" id="liAdvanceSearch">
<a href="#" title="Advanced Search">Advanced Search</a>
</li>
<li class="page_item" id="liCharts">
<a href="#" title="Charts" >Charts</a> <!--
</li>
</ul>
</div>
</div>
</div>
<div class="wrapper clear">
<div class="Welcome ">
<div class="welcome">
Welcome! <strong>Searcher</strong> …Run Code Online (Sandbox Code Playgroud) 我有一个带有可选字段的注册表单,但如果输入任何值,则应该超过2个字符.如果用户将该字段留空,如何跳过验证?
<h:inputText id ="fooid" maxlength="50" tabindex="4" value="#{registrationBean.foo}" validatorMessage="Please enter two or more characters">
<f:validateRegex pattern="^[A-Za-z-_./\s]{2,50}$"/>
<f:ajax event="blur" render="fooPanel" />
</h:inputText>
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
当试图添加一个 TODO在Facelets文件中的一段JavaScript代码中注释时
<script type="text/javascript">
<!--
// TODO -- my comment
function makeExecute() {
}
-->
</script>
Run Code Online (Sandbox Code Playgroud)
然后我面临一个例外:
javax.faces.view.facelets.FaceletException: Error Parsing /myScreen.xhtml:
Error Traced[line: 448] The string "--" is not permitted within comments.
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:390)
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:364)
at com.sun.faces.facelets.compiler.Compiler.compile(Compiler.java:122)
Run Code Online (Sandbox Code Playgroud)
这是怎么造成的,我该如何解决?
我在 IE 上的 jsf 页面不会在 firefox 上显示任何内容,我至少可以获取文本。奇怪的是,没有错误,所以我不确定出了什么问题。我环顾四周寻找信息,甚至为页面添加了 af:view 但仍然没有。感谢您的时间。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j" >
<f:view contentType="text/html">
<h:head>
<title>QC-Form</title>
<link href="./css/styles.css"
rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">QC Form</h1>
<br/> <br/>
<font face="comic sans MS" size="2" color="#33CCFF">
<p><b>Enter the information below: </b> </p>
</font>
<h:form>
<font face="comic sans MS" size="2">
<h:panelGroup id="initialInfo">
<b>Your initials: </b>
<h:inputText value="#{qcFormBean.techNameValue}"/><br/>
<br/>
<b>Model #: </b>
<h:selectOneMenu value="#{qcFormBean.modelValue}">
<f:selectItem itemValue="3600" itemLabel="3600" />
<f:selectItem itemValue="7200" itemLabel="7200" />
<f:selectItem itemValue="8300" …Run Code Online (Sandbox Code Playgroud) 使用 Facelets 并编写一些 XHTML,我无法弄清楚如何创建一个元素,然后在稍后添加属性,例如在 xslt 中,如果您想有条件地添加一个属性:
<xsl:element name="div">
<xsl:attribute name="style">color:blue;</xsl:attribute>
</xsl:element>
Run Code Online (Sandbox Code Playgroud)
谷歌给出了一些类似于 JSP taglib 的例子
<jsp:element name="div">
<jsp:attribute name=".">...</jsp:attribute>
</jsp:element>
Run Code Online (Sandbox Code Playgroud)
该库未作为 Facelets 中的标准提供,并且搜索包含的库的文档不会显示任何明显的信息。
我有一个在.tld文件中注册的自定义JSF组件.当我声明如下时,它在JSP中工作正常:
<%@taglib uri="http://example.com/ui" prefix="ex"%>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试声明如下时,它在Facelets中不起作用:
<html xmlns:ex="http://example.com/ui">
Run Code Online (Sandbox Code Playgroud)
如何在Facelets中使用我的自定义JSF组件?