You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Rottstock, Sven" <Sv...@sungard.de> on 2007/12/07 10:23:13 UTC
[Trinidad] treeTable and disclosedRowKeys
Hi,
i have a strange behaviour with the treeTable and the disclosedRowKeys.
In detail i want to expand specific nodes programaticaly and this should
be the initial state of the treeTable. This works fine for the first
render time. Now the trouble: In the action facet i have a commandLink
that should reset the nodes to the initial state. All that i can see is
that the treeTable is completely collapsed after you have clicked the
commandLink. If you force a refresh in the browser the initial state is
displayed again. In the other hand if you expand the nodes manually and
force a refresh in the browser the same state of the nodes are
displayed. In other words it is no request scope problem. For better
understanding i will provide some code snippets:
<!-- faces-config -->
<managed-bean>
<managed-bean-name>activityInstanceDetails</managed-bean-name>
<managed-bean-class>
local.jsf.beans.ActivityInstanceDetailsBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<!-- end faces-config -->
<!-- treeTable page -->
<tr:treeTable
disclosedRowKeys="#{activityInstanceDetails.disclosedRowKeys}"
value="#{activityInstanceDetails.dataModel}" var="row"
id="activityTree"
rowDisclosureListener="#{activityInstanceDetails.rowDisclosureListener}"
partialTriggers=":activityTree:collapseUninterested">
<f:facet name="actions">
<tr:commandLink text="Expand only current activity path"
id="collapseUninterested"
action="#{activityInstanceDetails.resetDisclosedRowKeys}"
partialSubmit="true" immediate="true"/>
</f:facet>
<f:facet name="nodeStamp">
<tr:column noWrap="true">
<f:facet name="header">
<tr:outputText value="#{bundle.name}"/>
</f:facet>
<tr:outputText value="#{row.runtimeObject.activity.name}"
inlineStyle="font-weight:bold" />
</tr:column>
</f:facet>
<!-- end treeTable page -->
<!-- activityInstanceDetails -->
public class ActivityInstanceDetailsBean {
private RowKeySet disclosedEntries;
private TreeModel dataModel;
public ActivityInstanceDetailsBean()
{
SessionContext ctx = SessionContext.findSessionContext();
disclosedEntries = (RowKeySet)ctx.lookup(DISCLOSED_ENTRIES);
dataModel = (TreeModel)ctx.lookup(DATA_MODEL);
}
public TreeModel getDataModel()
{
return dataModel;
}
private RowKeySet getInitialDisclosedRowKeys()
{
RowKeySet disclosedEntries = new RowKeySetTreeImpl();
TreeModel treeModel = getDataModel();
disclosedEntries.setCollectionModel(treeModel);
if (treeModel != null && treeModel.getRowCount() > 0) {
setActivityInstancePath(disclosedEntries, treeModel,
getActivityInstance());
}
return disclosedEntries;
}
public RowKeySet getDisclosedRowKeys()
{
if (disclosedEntries == null) {
disclosedEntries = getInitialDisclosedRowKeys();
SessionContext.findSessionContext().bind(
DISCLOSED_ENTRIES, disclosedEntries);
}
return disclosedEntries;
}
public void setDisclosedRowKeys(RowKeySet disclosedEntries) {
this.disclosedEntries = disclosedEntries;
SessionContext.findSessionContext().bind(DISCLOSED_ENTRIES,
disclosedEntries);
}
public void resetDisclosedRowKeys() {
setDisclosedRowKeys(getInitialDisclosedRowKeys());
}
public void rowDisclosureListener(RowDisclosureEvent event)
{
RowKeySet added = event.getAddedSet();
RowKeySet removed = event.getRemovedSet();
if(disclosedEntries == null)
{
disclosedEntries = added;
}
else
{
if(!added.isEmpty())
{
disclosedEntries.addAll(added);
}
if(!removed.isEmpty())
{
disclosedEntries.removeAll(removed);
}
}
}
}
<!-- end activityInstanceDetails -->
Hope that anybody can help me to solve this problem.
Regars,
Sven
Re: [Trinidad] treeTable and disclosedRowKeys
Posted by omaji7 <om...@gmail.com>.
Hi,
My project is build in JSF, Hibernate and Faclets. i m using trinidad
treetable tag to build a tree with multiselection nodes. Now i m facing a
problem to initially selection of the nodes when page is loaded at the first
time. i have tried alot to accomplish this task, but still unable to retain
it. There is an attribute of "selectedRowKeys" in TreeTable which takes the
object of "RowKeySet", but when i am building the tree in my bean, i don't
know the RowKeys generated, so how do i get my desired RowKeys to be
selected in the tree?
i am trying to provide the code below
myTree.xhtml
<tr:treeTable id="testTreeTable"
value="#{RoleManageBean.tree}"
var="node"
rowSelection="multiple"
initiallyExpanded="true"
rowBandingInterval="1"
horizontalGridVisible="true"
verticalGridVisible="true"
selectedRowKeys="#{RoleManageBean.selectedRowKeys}">
<f:facet name="actions">
<tr:commandButton id="treeTableSelectButton"
text="Submit Sel." action="#{RoleManageBean.treeTableSelect}" />
</f:facet>
<f:facet name="nodeStamp">
<tr:column headerText="Name">
<tr:outputText value="#{node.name}"/>
</tr:column>
</f:facet>
<f:facet name="pathStamp">
<tr:outputText value="#{node.name}"/>
</f:facet>
</tr:treeTable>
MyBean.java
public class RoleManageBean implements Serializable {
private TreeModel tree;
private RowKeySet selectedRowKeys = null;
public TreeModel getTree() throws Exception {
Application[] applications = dbops.getAllApplications();
List<Node1> empty1 = Collections.emptyList();
List<Node1> root1 = new ArrayList<Node1>();
List<Node1> apps = new ArrayList<Node1>();
for (Application application : applications) {
Set<ApplicationPage> appPages =
application.getApplicationPage();
List<Node1> pages = new ArrayList<Node1>();
for (ApplicationPage applicationPage : appPages) {
pages.add(new Node1(applicationPage.getPageName(),
String.valueOf(applicationPage.getPageID()), empty1));
}
apps.add(new Node1(application.getApplicationName(),
String.valueOf(application.getHomePage().getPageID()), pages));
}
root1.add(new Node1("Applications", "0", apps));
tree = new ChildPropertyTreeModel(root1, "children");
return tree;
}
public RowKeySet getSelectedRowKeys() {
selectedRowKeys = new RowKeySetImpl();
selectedRowKeys.add(String.valueOf("1,0"));
System.out.println("called");
return selectedRowKeys;
}
public void setSelectedRowKeys(RowKeySet selectedRowKeys) {
this.selectedRowKeys = selectedRowKeys;
}
Any guideline will be appriciated. Thanks in Advance
Majid.
Rottstock, Sven wrote:
>
> Hi,
>
> i have a strange behaviour with the treeTable and the disclosedRowKeys.
> In detail i want to expand specific nodes programaticaly and this should
> be the initial state of the treeTable. This works fine for the first
> render time. Now the trouble: In the action facet i have a commandLink
> that should reset the nodes to the initial state. All that i can see is
> that the treeTable is completely collapsed after you have clicked the
> commandLink. If you force a refresh in the browser the initial state is
> displayed again. In the other hand if you expand the nodes manually and
> force a refresh in the browser the same state of the nodes are
> displayed. In other words it is no request scope problem. For better
> understanding i will provide some code snippets:
>
> <!-- faces-config -->
> <managed-bean>
> <managed-bean-name>activityInstanceDetails</managed-bean-name>
> <managed-bean-class>
> local.jsf.beans.ActivityInstanceDetailsBean
> </managed-bean-class>
> <managed-bean-scope>request</managed-bean-scope>
> </managed-bean>
> <!-- end faces-config -->
>
> <!-- treeTable page -->
> <tr:treeTable
> disclosedRowKeys="#{activityInstanceDetails.disclosedRowKeys}"
> value="#{activityInstanceDetails.dataModel}" var="row"
> id="activityTree"
>
> rowDisclosureListener="#{activityInstanceDetails.rowDisclosureListener}"
> partialTriggers=":activityTree:collapseUninterested">
> <f:facet name="actions">
> <tr:commandLink text="Expand only current activity path"
> id="collapseUninterested"
> action="#{activityInstanceDetails.resetDisclosedRowKeys}"
> partialSubmit="true" immediate="true"/>
> </f:facet>
> <f:facet name="nodeStamp">
> <tr:column noWrap="true">
> <f:facet name="header">
> <tr:outputText value="#{bundle.name}"/>
> </f:facet>
> <tr:outputText value="#{row.runtimeObject.activity.name}"
> inlineStyle="font-weight:bold" />
> </tr:column>
> </f:facet>
> <!-- end treeTable page -->
>
> <!-- activityInstanceDetails -->
> public class ActivityInstanceDetailsBean {
> private RowKeySet disclosedEntries;
> private TreeModel dataModel;
>
> public ActivityInstanceDetailsBean()
> {
> SessionContext ctx = SessionContext.findSessionContext();
> disclosedEntries = (RowKeySet)ctx.lookup(DISCLOSED_ENTRIES);
> dataModel = (TreeModel)ctx.lookup(DATA_MODEL);
> }
>
> public TreeModel getDataModel()
> {
> return dataModel;
> }
>
> private RowKeySet getInitialDisclosedRowKeys()
> {
> RowKeySet disclosedEntries = new RowKeySetTreeImpl();
> TreeModel treeModel = getDataModel();
> disclosedEntries.setCollectionModel(treeModel);
> if (treeModel != null && treeModel.getRowCount() > 0) {
> setActivityInstancePath(disclosedEntries, treeModel,
> getActivityInstance());
> }
> return disclosedEntries;
> }
>
> public RowKeySet getDisclosedRowKeys()
> {
> if (disclosedEntries == null) {
> disclosedEntries = getInitialDisclosedRowKeys();
> SessionContext.findSessionContext().bind(
> DISCLOSED_ENTRIES, disclosedEntries);
> }
> return disclosedEntries;
> }
>
> public void setDisclosedRowKeys(RowKeySet disclosedEntries) {
> this.disclosedEntries = disclosedEntries;
> SessionContext.findSessionContext().bind(DISCLOSED_ENTRIES,
> disclosedEntries);
> }
>
> public void resetDisclosedRowKeys() {
> setDisclosedRowKeys(getInitialDisclosedRowKeys());
> }
>
> public void rowDisclosureListener(RowDisclosureEvent event)
> {
> RowKeySet added = event.getAddedSet();
> RowKeySet removed = event.getRemovedSet();
> if(disclosedEntries == null)
> {
> disclosedEntries = added;
> }
> else
> {
> if(!added.isEmpty())
> {
> disclosedEntries.addAll(added);
> }
> if(!removed.isEmpty())
> {
> disclosedEntries.removeAll(removed);
> }
> }
> }
> }
> <!-- end activityInstanceDetails -->
>
> Hope that anybody can help me to solve this problem.
>
> Regars,
>
> Sven
>
>
--
View this message in context: http://old.nabble.com/-Trinidad--treeTable-and-disclosedRowKeys-tp14209441p26841526.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.