在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存放在这里?
我不确定使用<f:view>和有什么好处<f:subview>.我注意到可以在不使用它们的情况下编写JSF页面.
使用这些标签有什么好处?
我有一个XHTML页面,提交回归自己.辅助bean是会话范围的.在重定向到自身时,页面呈现h:datatable两次,并给我重复的id错误.我可以直观地看到表格被渲染两次,彼此相邻.
**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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:form >
<h:dataTable binding="#{ecole.dataTable}" value="#{ecole.getEcoleList()}" var="c"
border="0" width="100%" cellpadding="0" cellspacing="0"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
<h:column>
<f:facet name="header">
ID
</f:facet>
#{c.idEcole}
</h:column>
<h:column>
<f:facet name="header">
Nom
</f:facet>
#{c.nomEcole}
</h:column>
<h:column>
<f:facet name="header">
Description
</f:facet>
#{c.desc_ecl}
</h:column>
<h:column>
<f:facet styleclass="options-width" name="header">
Options
</f:facet>
<h:commandLink action="#{ecole.editEcoleItem()}" title="Edit" >
<h:graphicImage style="border:0" url="/icones/b_edit.png" />
</h:commandLink>
   
<h:commandLink title="Delete"
onclick="return confirm('Voulez-vous confirmer la suppression?') ;"
action="#{ecole.deleteEcole(c)}"
>
<h:graphicImage …Run Code Online (Sandbox Code Playgroud) 我在我的公司"继承"了一个JSF 2(JSF 2.2.7)应用程序并面临java.lang.IllegalStateException,因为两个组件似乎具有相同的ID.
视图的结构如下(为了说明目的,我提取了相关代码,它可能包含一些拼写错误/无效语法,因为我更改了一些名称):
<p:commandButton id="editButton"
action="#{controller.prepareItem()}"
update=":itemEditDlg" oncomplete="PF('itemtEditDlg').show()" />
<comp:editItemDlg id="itemEditDlg" />
<p:dialog id="anotherDlg" >
<h:form id="anotherForm">
<c:forEach items="#{controller.allArgs}" var="arg" >
<!-- next line is the problem -->
<comp:mycomponent arg="#{arg}" />
</c:forEach>
</h:form>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
mycomponent.xhtml如下所示:
<cc:interface>
<cc:attribute name="arg" required="true" />
</cc:interface>
<cc:implementation>
<p:inputText id="argValue" value="#{cc.attrs.arg}" />
<p:message id="argValueMessage" for="argValue" />
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)
重要:mycomponent组件也在editItemDlg中使用(与"anotherDlg"中的方式相同),即在对话框和forEach循环中)
如果我点击editButton,我得到:
java.lang.IllegalArgumentException: Component ID anotherForm:j_idt192:argValue
has already been found in the view.
Run Code Online (Sandbox Code Playgroud)
它相当奇怪,因为"anotherDlg"在这种情况下并不是开放的,但显然已经渲染了.
我在StackTrace中获得以下信息(仅显示相关部分):
+id: j_idt192
type: javax.faces.component.UINamingContainer@399bd0dc
+id: j_id2
type: javax.faces.component.UIPanel@24ad3910
+id: argValue <===============
type: org.primefaces.component.inputtext.InputText@687d5c3f …Run Code Online (Sandbox Code Playgroud) 当使用 JSF Web 应用程序框架时,表单内元素的 ID 可以由框架自动生成,并且当组件驻留在其 ID 为 的表单中时,框架会自动为该元素form1生成 形式的 ID 。form1:foo虽然可以关闭此功能,但我想知道是否可以为其 ID 格式为 的元素定义 CSS ID 选择器foo:bar。
提前致谢。
我正在尝试<p:tab>动态添加PrimeFaces .在添加第二个选项卡时,我收到以下异常:
"java.lang.IllegalStateException:组件ID tab0已在视图中找到".
我怎么解决这个问题?
这是视图代码:
<h:form prependId="false">
<p:tabView id="tabview" dynamic="true" cache="false"
binding="#{testBean.tabView}"
activeIndex="#{testBean.activeTab}" >
<h:commandButton value="Close" action="#{testBean.removeTab}"/>
</p:tabView>
<h:commandButton value="Add Tab" action="#{testBean.addTab}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
这是bean代码:
public String addTab() {
String tabId="tab"+id;
System.out.println("Gen Id: "+tabId);
tab = new Tab();
tab.setTitle("Title: "+tabId);
tab.setId(tabId);
System.out.println("Tab Id: "+tab.getId());
tabView.getChildren().add(id,this.tab);
id++;
return "tabtest.jsf";
}
public String removeTab() {
tabView.getChildren().remove(activeTab);
return "tabtest.jsf";
}
Run Code Online (Sandbox Code Playgroud) Mojara 2.1.21
我根据评论更新了我的问题.我有两种情况,组件绑定到服务器会话bean.(附加链接信息:绑定属性导致在视图中找到重复的组件ID,并且/sf/answers/875887071/)
版本1:
single.xhtml:
<h:outputText value=... binding="#{mysessionbean.out}" />
Run Code Online (Sandbox Code Playgroud)
Java的:
@SessionScoped @Named public class Mysessionbean {
UIOutput out;
//getter and setter ....
}
Run Code Online (Sandbox Code Playgroud)
版本2:
所引用:
<h:outputText value=... binding="#{mysessionbean.out}"
Run Code Online (Sandbox Code Playgroud)
view1.xhtml:
<ui:composition template="template.xhtml" />
Run Code Online (Sandbox Code Playgroud)
view2.xhtml:
<ui:composition template="template.xhtml" />
Run Code Online (Sandbox Code Playgroud)
Java的:
@SessionScoped @Named public class Mysessionbean {
UIOutput out;
//getter and setter ....
}
Run Code Online (Sandbox Code Playgroud)
版本1没问题.(至少我到目前为止没有遇到任何错误).但是在版本2中,如果我从一个页面导航到另一个页面,则会出现重复ID错误.为什么会这样?使用(请求范围的)组件(在版本1中)与会话作用域绑定是否安全?还有其他用例需要考虑吗?
编辑: 功能要求1:
我想在视图中使用Primefaces数据表.我需要来自这个数据表的一些信息.(例如选定的行或行索引).因此绑定数据表有助于我检索此信息.
功能要求2:
组件在复合组件中的绑定.它们将绑定到会话范围的bean.(主要用在一个页面上,但是如果我在另一个页面上使用它会怎么样?
要求3
"版本2"中的情况.带有primefaces菜单和会话作用域绑定的模板.为此,我使用了EL-Binding.