当用户单击一行时,如何导航到不同的页面?
我希望能够在用户单击行时导航到不同的页面。
问题
- 没有抛出错误我可以看到
selectionListener
以预期的行值执行,但没有任何反应。 - 这是正确的方法吗?即使用我的动作侦听器来实现此目的。
支持豆是这个。
支持 bean
package com.howto;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.DataModel;
import org.richfaces.component.UIExtendedDataTable;
@ManagedBean(name = "backingBean")
@SessionScoped
public class BackingBean {
private List<String> names;
private DataModel<String> name;
private String rowValue;
// private List<String> selection;
private Collection<String> selection;
@PostConstruct
public void init() {
names = new ArrayList<String>();
names.add("MyName");
names.add("YourName");
names.add("OurName");
names.add("MamaDidNotGiveOne");
}
public void update() {
System.out.println("Somebody clicked "
+ name);
}
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public DataModel<String> getName() {
return name;
}
public void setName(DataModel<String> name) {
this.name = name;
}
public String selectionListener(AjaxBehaviorEvent event) {
UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
Object originalKey = dataTable.getRowKey();
// selectionItems.clear();
for (Object selectionKey : selection) {
dataTable.setRowKey(selectionKey);
if (dataTable.isRowAvailable()) {
//selectionItems.add((InventoryItem) dataTable.getRowData());
rowValue = (String) dataTable.getRowData();
}
}
dataTable.setRowKey(originalKey);
return "success";
}
public String gotopage() {
return "success";
}
public Collection<String> getSelection() {
return selection;
}
public void setSelection(Collection<String> selection) {
this.selection = selection;
}
public String getRowValue() {
return rowValue;
}
public void setRowValue(String rowValue) {
this.rowValue = rowValue;
}
}
方法selectionListener
每次用户单击行项目时都会被命中,不会引发错误,但什么也不会发生。
XHTML
<h:form>
<rich:extendedDataTable
value="#{backingBean.names}" var="rowItem"
selection="#{backingBean.selection}" id="table"
frozenColumns="2" style="height:300px; width:500px;" selectionMode="single">
<a4j:ajax event="selectionchange" listener="#{backingBean.selectionListener}" />
<rich:column>
<f:facet name="header">
<h:outputText value="vendor" />
</f:facet>
<h:outputText value="#{rowItem}" />
</rich:column>
</rich:extendedDataTable>
</h:form>
导航规则
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-action>#{backingBean.selectionListener}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/pages/dummyfolder/results.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
使用Richfaces 4找不到带有版本的标签。
I want to be able to navigate to a different page when user clicks are row.
Problems
- No error is thrown I can see the
selectionListener
getting executed with expected row value but nothing happens. - Is this the right way of doing it i.e. using my action listener for this purpose.
Backing bean is this.
Backing bean
package com.howto;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.DataModel;
import org.richfaces.component.UIExtendedDataTable;
@ManagedBean(name = "backingBean")
@SessionScoped
public class BackingBean {
private List<String> names;
private DataModel<String> name;
private String rowValue;
// private List<String> selection;
private Collection<String> selection;
@PostConstruct
public void init() {
names = new ArrayList<String>();
names.add("MyName");
names.add("YourName");
names.add("OurName");
names.add("MamaDidNotGiveOne");
}
public void update() {
System.out.println("Somebody clicked "
+ name);
}
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public DataModel<String> getName() {
return name;
}
public void setName(DataModel<String> name) {
this.name = name;
}
public String selectionListener(AjaxBehaviorEvent event) {
UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
Object originalKey = dataTable.getRowKey();
// selectionItems.clear();
for (Object selectionKey : selection) {
dataTable.setRowKey(selectionKey);
if (dataTable.isRowAvailable()) {
//selectionItems.add((InventoryItem) dataTable.getRowData());
rowValue = (String) dataTable.getRowData();
}
}
dataTable.setRowKey(originalKey);
return "success";
}
public String gotopage() {
return "success";
}
public Collection<String> getSelection() {
return selection;
}
public void setSelection(Collection<String> selection) {
this.selection = selection;
}
public String getRowValue() {
return rowValue;
}
public void setRowValue(String rowValue) {
this.rowValue = rowValue;
}
}
Method selectionListener
does get hit every time user clicks a row item no error is thrown but nothing happens.
XHTML
<h:form>
<rich:extendedDataTable
value="#{backingBean.names}" var="rowItem"
selection="#{backingBean.selection}" id="table"
frozenColumns="2" style="height:300px; width:500px;" selectionMode="single">
<a4j:ajax event="selectionchange" listener="#{backingBean.selectionListener}" />
<rich:column>
<f:facet name="header">
<h:outputText value="vendor" />
</f:facet>
<h:outputText value="#{rowItem}" />
</rich:column>
</rich:extendedDataTable>
</h:form>
Navigation Rule
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-action>#{backingBean.selectionListener}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/pages/dummyfolder/results.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Using Richfaces 4 could not find a tag with version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过从操作侦听器方法返回
String
来进行导航。你只能用实际的行动方法来做到这一点。您需要将方法返回类型设置回void
并在NavigationHandler#handleNavigation()
。You can't navigate by returning
String
from an action listener method. You can only do this in real action methods. You need to set the method return type back tovoid
and take the navigation in your own hands with help ofNavigationHandler#handleNavigation()
.