我想有条件地输出一些Facelets代码.
为此,JSTL标签似乎工作正常:
<c:if test="${lpc.verbose}">
...
</c:if>
Run Code Online (Sandbox Code Playgroud)
但是,我不确定这是否是最佳做法?还有另一种方法来实现我的目标吗?
任何人都可以澄清我们如何在一般情况下使用,或者在现实世界中使用这个代码片段?
<f:metadata>
<f:viewParam id="id" value="#{bean.id}" />
<f:viewAction action="#{bean.init}" />
</f:metadata>
Run Code Online (Sandbox Code Playgroud) 我最近开始使用带有Facelets的JSF 2.0,并且对于了解<ui:include>Facelets 1.x提供的现有和其他模板技术的新复合组件感到困惑.
这些方法有什么区别?从功能上看,它们似乎提供了相同的:<ui:param>vs <cc:attribute>,<ui:insert>+ <ui:define>vs标记文件,重用现有模板.除了复合组件的语法和清晰的接口规范之外还有什么吗?性能会有所不同?
在JSF中有很多材料区分value属性和binding属性.
我对这两种方法如何彼此不同感兴趣.鉴于:
public class User {
private String name;
private UICommand link;
// Getters and setters omitted.
}
Run Code Online (Sandbox Code Playgroud)
<h:form>
<h:commandLink binding="#{user.link}" value="#{user.name}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
value指定属性时会发生什么变化.getter运行以返回bean 的name属性值User.该值将打印到HTML输出.
但我无法理解它是如何binding运作的.生成的HTML如何维护与bean link属性的绑定User?
下面是手动美化和注释后生成的输出的相关部分(注意id j_id_jsp_1847466274_1是自动生成的,并且有两个隐藏的输入小部件).我正在使用Sun的JSF RI 1.2版.
<form action="/TestJSF/main.jsf" enctype="application/x-www-form-urlencoded"
id="j_id_jsp_1847466274_1" method="post" name="j_id_jsp_1847466274_1">
<input name="j_id_jsp_1847466274_1" type="hidden" value="j_id_jsp_1847466274_1">
<a href="#" onclick="...">Name</a>
<input autocomplete="off" id="javax.faces.ViewState" name="javax.faces.ViewState"
type="hidden" value="-908991273579182886:-7278326187282654551">
</form>
Run Code Online (Sandbox Code Playgroud)
在哪里binding存放在这里?
如何在JBoss服务器中升级Mojarra并告诉它使用给定的Mojarra 2.x JAR而不是JBoss自带的,jboss-jsf-api_2.1_spec-2.0.1.Final.jar如启动日志中所示?
如果这是相关的,我目前正在使用JBoss AS 7.1.
我在panelGrids中有很多outputLabel和inputText对
<h:panelGrid columns="2">
<h:outputLabel value="label1" for="inputId1"/>
<h:inputText id="inputId1/>
<h:outputLabel value="label2" for="inputId2"/>
<h:inputText id="inputId2/>
...
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
我希望所有这些都有一些行为:比如每个inputText的相同验证或相同大小.所以我创建了一个复合组件,它只包含一个outputLabel和一个inputText
<my:editField value="field1"/>
<my:editField value="field2"/>
Run Code Online (Sandbox Code Playgroud)
但是现在当我将它们放在gridPanel中时,根据标签文本的长度,它们不会对齐.我理解为什么,但我不知道如何解决.
我正在用Mojarra JSF编写自定义表复合组件.我也试图将该组合绑定到支持组件.目的是能够指定表在复合属性中具有的元素数量,稍后绑定的后备组件将在呈现视图之前自动生成元素本身.我有这个示例代码:
主页:
<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:comp="http://java.sun.com/jsf/composite/comp">
<h:head />
<body>
<h:form>
<comp:myTable itemNumber="2" />
</h:form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
myTable.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<composite:interface componentType="components.myTable">
<composite:attribute name="itemNumber"
type="java.lang.Integer" required="true" />
</composite:interface>
<composite:implementation>
<h:dataTable value="#{cc.values}" var="value">
<h:column headerText="column">
#{value}
<h:commandButton value="Action" action="#{cc.action}" />
</h:column>
</h:dataTable>
</composite:implementation>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
MyTable.java:
@FacesComponent("components.myTable")
public class MyTable extends UINamingContainer {
private List<String> values = new ArrayList<String>();
public void action() {
System.out.println("Called");
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
// Initialize the list …Run Code Online (Sandbox Code Playgroud) 我正在使用JSF 2.0.我使用tagfiles创建了自定义JSTL标记,并且在JSP中运行良好.但我也想在Facelets中使用自定义JSTL标签.是否可以在Facelets中创建标签文件?
我想在我的页面中设置一个Date字段
|hours| h |minutes|
Run Code Online (Sandbox Code Playgroud)
小时和分钟在分开的inputText中.
豆有这个日期
import java.util.Date;
...
private Date myDate;
...
Run Code Online (Sandbox Code Playgroud)
而页面是
<h:form>
...
<h:inputText id="myDateHours" maxlength="2" value="#{myBean.myDate}"
<f:convertDateTime pattern="HH" />
</h:inputText>
<h:outputText value=" h " />
<h:inputText id="myDateMinutes" maxlength="2" value="#{myBean.myDate}"
<f:convertDateTime pattern="mm" />
</h:inputText>
...
</h:form>
Run Code Online (Sandbox Code Playgroud)
但问题是,当我提交表单时,只保存最后一个元素.例如,如果我键入小时数,然后输入分钟数,则会覆盖小时数,结果为
| 00 | h | minutes |
Run Code Online (Sandbox Code Playgroud)
我试着设定
<h:inputText id="myDateHours" value="#{myBean.myDate.hours}></h:inputText>
<h:inputText id="myDateMinutes" value="#{myBean.myDate.minutes}></h:inputText>
Run Code Online (Sandbox Code Playgroud)
但我得到了
Cannot convert 01/01/70 01:00 of type class java.util.Date to int
Run Code Online (Sandbox Code Playgroud)
我不想用两个int字段替换我的日期字段(小时和分钟......)你有什么想法吗?
谢谢
jsf ×8
jsf-2 ×8
facelets ×3
tagfile ×2
alignment ×1
binding ×1
components ×1
converter ×1
custom-tags ×1
date ×1
grid ×1
input ×1
jboss ×1
jstl ×1
mojarra ×1
viewaction ×1
viewparams ×1
wildfly ×1