jsf2中表内的selectonemenu
我有一个包含 2 个 selectOneMenu 组件的表。
我希望一旦在第一个 selectOneMenu 组件中选择一条记录,它将使用 Ajax 更新同一行中的另一个 selectOneMenu 。
我的表:
<p:dataTable value="#{myBean.myInfo}" var="myInfo">
<p:column>
<f:facet name="header">Group</f:facet>
<h:selectOneMenu value="#{myInfo.myInfoType.code}">
<f:selectItems value="#{myBean.myList}" />
<f:ajax event="change" execute="@this" listener="#{myBean.refershNames}" render="myNames"/>
</h:selectOneMenu>
</p:column>
<p:column>
<f:facet name="header">Name</f:facet>
<h:selectOneMenu id="myNames" value="#{myInfo.myInfoType.secondCode}">
<f:selectItems value="#{myBean.mySecondList}" />
</h:selectOneMenu>
</p:column>
<p:dataTable>
在我的 bean 中:
List<SelectItem> myList,mySecondList;
public void refershNames(AjaxBehaviorEvent event){
//how can I retrieve the selected item and update the relevant record?
}
我怎样才能用 Ajax 做到这一点?我正在使用 JSF2
I have a table with 2 selectOneMenu components.
I would like that once a record was chosen in the first selectOneMenu component it will update the other selectOneMenu with Ajax in the same row.
My table:
<p:dataTable value="#{myBean.myInfo}" var="myInfo">
<p:column>
<f:facet name="header">Group</f:facet>
<h:selectOneMenu value="#{myInfo.myInfoType.code}">
<f:selectItems value="#{myBean.myList}" />
<f:ajax event="change" execute="@this" listener="#{myBean.refershNames}" render="myNames"/>
</h:selectOneMenu>
</p:column>
<p:column>
<f:facet name="header">Name</f:facet>
<h:selectOneMenu id="myNames" value="#{myInfo.myInfoType.secondCode}">
<f:selectItems value="#{myBean.mySecondList}" />
</h:selectOneMenu>
</p:column>
<p:dataTable>
In the bean I have:
List<SelectItem> myList,mySecondList;
public void refershNames(AjaxBehaviorEvent event){
//how can I retrieve the selected item and update the relevant record?
}
How can I do it with Ajax? I am using JSF2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将数据表值包装在
DataModel< 中/code>
以便您可以通过
DataModel#getRowData()
。因此,根据
评论
更新,这是我在您告诉它不起作用后创建的测试用例。它对我来说适用于 Tomcat 7.0.5 和 Glassfish 3.0.1 上的 Mojarra 2.0.3。
com.example.Item
com.example.Bean
test.xhtml
此测试用例证明,每当您更改第一列中的下拉值时,同一行第二列中的下拉值将被反映以检索相同的值。
Wrap the datatable value in
DataModel<E>
so that you can obtain themyInfo
object in question byDataModel#getRowData()
. So,with
and
Update as per the comments, here is the testcase I created after you told that it didn't work. It worked for me with Mojarra 2.0.3 on both Tomcat 7.0.5 and Glassfish 3.0.1.
com.example.Item
com.example.Bean
test.xhtml
This testcase proves that whenever you change a dropdown value in the 1st column, then the dropdown value in the 2nd column in the same row will be reflected to retrieve the same value.
我遇到了同样的问题,经过大量的试验和错误,这对我有用
valuechangelistener 是
这很简单并且对我来说非常适合,因为我在第一列中选择的消息更新了第二列中的选项并通过 ajax 完成。但话又说回来,我仍在学习,我对 jsf 的很多知识都来自 @BalusC 博客的材料:),所以如果这种方法有一些缺陷,请让我知道。
i had the same issue and after a lot of trial and error this worked for me
valuechangelistener is
This is simple and works perfectly for me , as the message that i choose in the first column updates the options in the second column and its done through ajax. But then again, i m still learning and alot of my knowledge of jsf is from material from @BalusC blog :), so if this approach has some flaws, please lemme know.