0
我想在用戶單擊行時能夠導航到不同的頁面。
問題
用戶單擊某一行時,如何導航到其他頁面?
- 不引發錯誤,我可以看到
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找不到配版的標籤。