Richfaces:更改组件的“渲染”方式a4j 的属性值:extendDataTable 中的支持
我尝试将 richfaces ExtendedDataTable 与 a4j:support 一起使用来更改 rich:panel 的“渲染”属性值,但它不起作用。
这是我的 JSF 页面的一部分,其中包含 rich:extendedDataTable 和 rich:panel:
<h:form id="tabForm">
<rich:extendedDataTable id="myTable" width="500px" height="250px"
value="#{extDataTableBean.extList}" var="dataRow"
selection="#{extDataTableBean.selection}" selectionMode="single">
<rich:column>
<f:facet name="header"><h:outputText value="ID" /></f:facet>
<h:outputText value="#{dataRow.id}"></h:outputText>
</rich:column>
<rich:column>
<f:facet name="header"><h:outputText value="Name" /></f:facet>
<h:outputText value="#{dataRow.name}"></h:outputText>
</rich:column>
<a4j:support id="myTableTakeSelection" action="#{extDataTableBean.takeSelection}" event="onselectionchange" reRender="pane" />
</rich:extendedDataTable>
</h:form>
<rich:panel id="pane" rendered="#{extDataTableBean.showPane}">
<h:form id="secForm">
<h:outputText value="ID : " />
<h:inputText id="inTextID" value="#{extDataTableBean.idFd}" />
<br/>
<h:outputText value="Name : " />
<h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
</h:form>
</rich:panel>
rich:panel 'rendered' 属性的默认值为 false(在支持 bean 中设置)。我想要实现的是,当选择 ExtendedDataTable 中的一行时,其值将更改为 true,以便它在 GUI 中可见。
这是我的支持 bean 的一部分:
/* Constructor */
public ExtDataTableBean(){
setShowPane(false); // default to false
loadDataList();
}
/* Load some test data into extendedDataTable */
public void loadDataList(){
extList = new ArrayList<MyData>();
MyData e1 = new MyData();
e1.setId(1);
e1.setName("name 1");
extList.add(e1);
MyData e2 = new MyData();
e2.setId(2);
e2.setName("name 2");
extList.add(e2);
}
public String takeSelection(){
Iterator iterator = getSelection().getKeys();
Object key = null;
while(iterator.hasNext()){
key = iterator.next();
}
/* set the values of inputText with value from selected row */
setIdFd(extList.get(Integer.parseInt(key.toString())).getId());
setNameFd(extList.get(Integer.parseInt(key.toString())).getName());
setShowPane(true);
return null;
}
public List<MyData> getExtList() {
/* Lazy loading */
if(extList == null){
loadDataList();
}
return extList;
}
在 takeSelection() 方法中,我使用 setShowPane(true) 将 rich:panel 'rendered' 属性的值更改为 true。问题很丰富:当选择一行时,面板在 GUI 中不可见。
我做了另一个简单的测试,添加 ah:commandButton 和 a4j:support 将 showPane 设置为 true,如下所示:
<h:commandButton id="cmdBtn" value="Show Pane">
<a4j:support id="cmdBtnSupport" reRender="pane" action="#{extDataTableBean.dispPane}" event="onclick" />
</h:commandButton>
并在支持 bean: 中,
public String dispPane(){
setShowPane(true);
return null;
}
它按预期工作。单击按钮后,rich:panel 在 GUI 中可见。
我的代码中遗漏了什么?
I'm trying to use richfaces extendedDataTable with a4j:support to change a rich:panel's 'rendered' attribute's value but it's not working.
This is part of my JSF page that contains a rich:extendedDataTable and a rich:panel:
<h:form id="tabForm">
<rich:extendedDataTable id="myTable" width="500px" height="250px"
value="#{extDataTableBean.extList}" var="dataRow"
selection="#{extDataTableBean.selection}" selectionMode="single">
<rich:column>
<f:facet name="header"><h:outputText value="ID" /></f:facet>
<h:outputText value="#{dataRow.id}"></h:outputText>
</rich:column>
<rich:column>
<f:facet name="header"><h:outputText value="Name" /></f:facet>
<h:outputText value="#{dataRow.name}"></h:outputText>
</rich:column>
<a4j:support id="myTableTakeSelection" action="#{extDataTableBean.takeSelection}" event="onselectionchange" reRender="pane" />
</rich:extendedDataTable>
</h:form>
<rich:panel id="pane" rendered="#{extDataTableBean.showPane}">
<h:form id="secForm">
<h:outputText value="ID : " />
<h:inputText id="inTextID" value="#{extDataTableBean.idFd}" />
<br/>
<h:outputText value="Name : " />
<h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
</h:form>
</rich:panel>
The default value of rich:panel 'rendered' attribute is false (set in the backing bean). What I wanted to achieve is when a row in the extendedDataTable is selected, its value is changed to true so that it is visible in GUI.
And this is part of my backing bean:
/* Constructor */
public ExtDataTableBean(){
setShowPane(false); // default to false
loadDataList();
}
/* Load some test data into extendedDataTable */
public void loadDataList(){
extList = new ArrayList<MyData>();
MyData e1 = new MyData();
e1.setId(1);
e1.setName("name 1");
extList.add(e1);
MyData e2 = new MyData();
e2.setId(2);
e2.setName("name 2");
extList.add(e2);
}
public String takeSelection(){
Iterator iterator = getSelection().getKeys();
Object key = null;
while(iterator.hasNext()){
key = iterator.next();
}
/* set the values of inputText with value from selected row */
setIdFd(extList.get(Integer.parseInt(key.toString())).getId());
setNameFd(extList.get(Integer.parseInt(key.toString())).getName());
setShowPane(true);
return null;
}
public List<MyData> getExtList() {
/* Lazy loading */
if(extList == null){
loadDataList();
}
return extList;
}
In the takeSelection( ) method I have setShowPane(true) to change the value of rich:panel 'rendered' attribute to true. The problem is rich:panel is not visible in the GUI when a row is selected.
I did another simple test by adding a h:commandButton with a4j:support to set showPane to true, like this:
<h:commandButton id="cmdBtn" value="Show Pane">
<a4j:support id="cmdBtnSupport" reRender="pane" action="#{extDataTableBean.dispPane}" event="onclick" />
</h:commandButton>
and in the backing bean:
public String dispPane(){
setShowPane(true);
return null;
}
and it is working as expected. rich:panel is visible in GUI after the button is clicked.
What did I miss in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我从这个网站找到了问题的原因:
http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering
摘录描述问题的部分:
因此,在我修改要重新渲染的部分并将其渲染绑定如下之后,它现在正在工作:
I think I found the cause of the problem from this website:
http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering
An extract on the part that described the problem:
So, after I modified the part to be rerendered and rendered binding to as follow then it is working now:
开箱即用,支持 Ajax。无需添加
标记,该标记旨在为非 ajax JSF 组件带来 ajax 功能,例如
。所以,试试这个:
祝你好运。
<rich:extendedDataTable>
is Ajax-enabled out of the box. No need to add the<a4j:support>
tag, which is intended to bring ajax functionality to non-ajax JSF components, such as<h:inputText>
.So, try this instead:
Good luck.