Selectonechoice's dependent

Forum sobre a ferramenta Oracle JDeveloper, ADF, OAF, etc. (Não é destinado ao aprendeziado da Linguagem Java em geral)
Post Reply
Mick
Rank: Programador Sênior
Rank: Programador Sênior
Posts: 69
Joined: Fri, 08 Feb 2008 11:20 am
Location: São Paulo - SP

Hello everyone ....

I have the following problem ...

I have two selectonchoices that are dependent, that is, as soon as I choose A value in the first selectionchoice, the second should show values ??related to the value I chose in the first:

Select all

 
<af:selectOneChoice label="Razão Social"  
                  binding="#{backing_Inscricao.razao_social}" 
                   autoSubmit="true" id="razao"  partialTriggers="plano"> 
       <f:selectItems value="#{backing_Inscricao.tipos}"/> 
</af:selectOneChoice> 
 
<af:selectOneChoice label="Tipo de Plano" 
                 binding="#{backing_Inscricao.plano}" 
                 autoSubmit="true" partialTriggers="razao"   id="plano"> 
     <f:selectItems value="#{backing_Inscricao.planos}"/> 
</af:selectOneChoice> 
and Baking Bean:

Select all

 
public SelectItem[] getPlanos() { 
            if(getRazao_social().getValue()!=null){ 
                 BindingContainer bindings = getBindings(); 
                 OperationBinding operationBinding =  
                               bindings.getOperationBinding("ExecuteWithParams4");                             operationBinding.getParamsMap().put("wcodigo_empresa",Integer.parseInt(getRazao_social().getValue().toString()) );     
                  Object result = operationBinding.execute(); 
                  if (!operationBinding.getErrors().isEmpty()) { 
                             return null; 
                    } 
             } 
 
            FacesContext fctx = FacesContext.getCurrentInstance(); 
            ValueBinding vbinding = fctx.getApplication().createValueBinding("#{bindings.Assoplanos_usuarioView1Iterator}"); 
            DCIteratorBinding locationsIterBinding = (DCIteratorBinding)vbinding.getValue(fctx); 
            locationsIterBinding.executeQuery(); 
            locationsIterBinding.setRangeSize(-1); 
 
           Row[] locRowsArray = locationsIterBinding.getAllRowsInRange(); 
           planos = new SelectItem[locRowsArray.length]; 
 
            for (int indx = 0; indx < locRowsArray.length; indx++) { 
                SelectItem addItem = new SelectItem(); 
                addItem.setLabel((String)locRowsArray[indx].getAttribute("Descricao")); 
                addItem.setValue(locRowsArray[indx].getAttribute("Codigo")); 
               planos[indx] = addItem; 
           } 
           return planos;               
    } 
 
public SelectItem[] getTipos() {  
 
            FacesContext fctx = FacesContext.getCurrentInstance(); 
            ValueBinding vbinding = fctx.getApplication().createValueBinding("#{bindings.Empresas_acessoView1Iterator}"); 
            DCIteratorBinding locationsIterBinding = DCIteratorBinding)vbinding.getValue(fctx); 
 
            locationsIterBinding.executeQuery(); 
            locationsIterBinding.setRangeSize(-1); 
            Row[] locRowsArray = locationsIterBinding.getAllRowsInRange(); 
            tipos = new SelectItem[locRowsArray.length]; 
 
            for (int indx = 0; indx < locRowsArray.length; indx++) { 
                SelectItem addItem = new SelectItem(); 
                addItem.setLabel((String)locRowsArray[indx].getAttribute("Razsoc")); 
                addItem.setValue(locRowsArray[indx].getAttribute("Codigo")); 
                tipos[indx] = addItem; 
            } 
            return tipos; 
    } 

It is working perfectly .. When I change the value in the first selectoncho the second is updated normally ... but when I choose a value in the second selectionchoice, and then I try change a value in the first .. it stops working ....: cry:

I tried to put a getPlano().resetvalue() ... to clean the second ... and it was working well ... but then when I click on a button to be able to send the data .. he is resetting também and sending the value in white !!! ....
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

Select all

 
<af:selectOneChoice id="tipoCliente" 
                                                        binding="#{manutencaoCompetenciaBean.tipoCliente}" 
                                                        value="#{bindings.Brcategoriacliid1.inputValue}" 
                                                        unselectedLabel="" 
                                                        inlineStyle="width: 250px" 
                                                        autoSubmit="true" 
                                                        valueChangeListener="#{manutencaoCompetenciaBean.atualizaGarantia}"> 
                                        <af:forEach items="#{bindings.CategoriasClientesVO1.rangeSet}" 
                                                    var="row"> 
                                            <af:selectItem value="#{row.Brcategoriacliid.sequenceNumber}" 
                                                           label="#{row.Brdescricao}" id="itemBrcategoriacliid"/> 
                                        </af:forEach> 
                                    </af:selectOneChoice> 
When I have to do this I use the forEach to have elements and the method valueChangeLister next to the partialtrigers attribute ...

in the end .. you are afraid to see where you are calling this resetvalue because it must be being called at the time of the submit of the form

or

] Implement a Valuechnelistener in the second in order to clean the first in case DDOs are different

Select all

 
    public void atualizaGarantia(ValueChangeEvent evt) 
    { 
    	Object valor = evt.getNewValue(); 
    	List<CoreSelectItem> listaValores = evt.getComponent().getChildren(); 
     } 
through this object EVT that is passed by parameter you have objects to the data of the object

I think your problem can be solved with this
Mick
Rank: Programador Sênior
Rank: Programador Sênior
Posts: 69
Joined: Fri, 08 Feb 2008 11:20 am
Location: São Paulo - SP

Thank you again, Victor .. !!!! : -I managed to solve my problem !! ...

I used the Valuechangelistener ..... and everything worked ....

now only one doubt .. when you use the foreach ... as you do to set the 'rangesize'
... because if the rangsize is different from -1, it will only show 10 lines, is not it? ... .
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

When I use Foreate I have to add the ITERATOR of the vo la in the paidedef so I put the rangeSize = -1 it even in the page def

anything tamo ai
good luck
Mick
Rank: Programador Sênior
Rank: Programador Sênior
Posts: 69
Joined: Fri, 08 Feb 2008 11:20 am
Location: São Paulo - SP

Ahh, I understand !!! :)
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests