Solved

Richfaces component

Posted on 2009-06-29
9
1,093 Views
Last Modified: 2013-11-24
Hi!

I've a small problem with a richface component, I cannot find what I do wrong:

I want to do:

A tree, listing categories of services. When we click on a final node, we display services of this categories.

When this is selected, we can "choose him" by clicking on a button(why this step? Because we will use different services for different actions).

Most of theses things works. But when I click on the commandbutton, the panel that display services in the current categorie) is not more shown. I've a "rendered" to display services only when we have a categorie selected.

Where am I wrong? I've the impression there is a "shortcut" between the ajax of the tree and the ajax of the command button, but what?
// JSF PART
 

                        <rich:panel id="serv" >

                            <f:facet name="header">

                                I want<br/>

                            </f:facet>

                            <h:panelGrid columns="2" width="100%" columnClasses="col" >

                                <rich:tree id="treetake" switchType="ajax" ajaxSubmitSelection="true" nodeSelectListener="#{AddDeal.processSelection}" >

                                    <rich:recursiveTreeNodesAdaptor roots="#{AddDeal.rootCat}" var="item" nodes="#{item.catServiceCollection}" />

                                </rich:tree>

                                

                                <a4j:outputPanel id="ajxpn1" ajaxRendered="true">     

                                    <h:selectOneListbox id="listservtake"  rendered="#{AddDeal.serv!=null}" value="#{AddDeal.currentService}">

                                        <f:selectItems  value="#{AddDeal.serv}"/>

                                    </h:selectOneListbox>

                                </a4j:outputPanel>

                            </h:panelGrid>

                        </rich:panel>

                        

                        <rich:panel id="moreinfo">

                            <f:facet name="header">

                                Choosed services<br/>

                            </f:facet>

                            <a4j:commandButton value="Request this service" reRender="rep1" >

                                <a4j:actionparam name="username" value="#{AddDeal.currentService}" assignTo="#{AddDeal.deal.idRequestedService}"/>

                            </a4j:commandButton>

                            <h:outputText id="rep1" value="#{AddDeal.deal.idRequestedService}"/>

                        </rich:panel>
 
 
 

//the bean part:

//I dont display getters and setters that haven't anything special
 

    public void processSelection(NodeSelectedEvent event) {//TODO check if it's a final node

        HtmlTree tree = (HtmlTree) event.getComponent();

        this.serv= ((CatService) tree.getRowData()).getServiceCollection();

    }
 

    public Collection<SelectItem> getServ(){

        if(this.serv == null || this.serv.size()==0) return null;

        

        ArrayList<SelectItem> col = new ArrayList<SelectItem>();        

        for(Service s: this.serv){

            col.add(new SelectItem(s));

        }

        return col;

    }
 

    public Deal getDeal() {

        if(deal ==null)

            deal = new Deal();

        return deal;

    }

Open in new window

0
Comment
Question by:Nargzul
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:supergokhan
ID: 24742800
I advise you try this first.

<a4j:commandButton value="Request this service" reRender="serv, moreinfo" >

so it will render them too.
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24744947
Hi,

I've try this, the list is always hidding when I click on the button.
0
 
LVL 1

Expert Comment

by:supergokhan
ID: 24745285
<h:selectOneListbox id="listservtake"  rendered="#{AddDeal.serv!=null}"

this calls the getServ method in the bean. And if this bean's scope is request
this.serv gets null because constructor can not call the processSelection to set that value.
Try making the bean's scope to session scope.
Or! change the getServ method like getServices
and
<h:selectOneListbox id="listservtake"  rendered="#{AddDeal.services!=null}"
0
 
LVL 1

Expert Comment

by:supergokhan
ID: 24745331
<h:selectOneListbox id="listservtake"  rendered="#{AddDeal.serv!=null}" value="#{AddDeal.currentService}">

for this you need a method like
getCurrentService()

I advise first try the scope to session.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:Nargzul
ID: 24745448
But If I do a session scope, I will have side effects no?

When start and end exactly the request scope? because for me it was since the generation of the page to the reception of the validation, no?


I've said I doesn't display dummy getters and setters, but I've:

public Service getCurrentService() {
        return currentService;
    }

I don't really understand your first message, your "OR".

What must I put in this getServices method? What the difference if I just change the name of the function?
0
 
LVL 1

Expert Comment

by:supergokhan
ID: 24746077
Hi again. It is not the names ok. I understand now. You populate the values when you first press the tree.When you populate listbox dynamically it will not be visible next time you press the button. Because it is a request scoped bean.Constructor clears it. You can do this.

<h:selectOneListbox id="listservtake"  rendered="#{AddDeal.serv!=null}" value="#{AddDeal.currentService}">
<f:selectItems  value="#{AddDeal.serv}"/>
</h:selectOneListbox>

as you see you have the value="#{AddDeal.currentService}">



For last if this bean is not so big make it session scope. Yhe populated values won't get cleared.

You wont change the bean scope but you need something in session so you will generate the listboxagain.


private Service currentService;

{

    fillSelectItems();

}
 

public Service fillSelectItems()

{

HtmlTree tree=(HtmlTree)getSession().getAttribute("tree")

this.serv= ((CatService) tree.getRowData()).getServiceCollection();

}
 

public void processSelection(NodeSelectedEvent event) {

        getSession().setAttribute("tree",event.getComponent);

        fillSelectItems();  

}

Open in new window

0
 
LVL 1

Author Comment

by:Nargzul
ID: 24845089
But with a session bean, if  the person is on the same page twice, it would no more work no?
0
 
LVL 1

Expert Comment

by:supergokhan
ID: 24847089
You wont use the session bean. You will use just the session.
0
 
LVL 1

Accepted Solution

by:
Nargzul earned 0 total points
ID: 24848971
"You wont use the session bean. You will use just the session."
???

"You wont change the bean scope but you need something in session so you will generate the listboxagain."

If we change the bean scope, it's because it's a bean ^^
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 87
Java Timer (static) 9 36
factorial example 4 35
Why my table column Id is not passed to java object? 4 28
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now