0

I am trying to add ajax behavior to selectoneradio with this code:

xhtml:

<h:selectOneRadio id="metalA" converter="metalConverter" value="#{backingBean.metal.metalCode">
    <f:selectItems value="#{backingBean.metalCodeRadio}" />
    <f:ajax listener="#{backingBean.updateMenu}" event="click" execute="metalA" render="metalTypeMenuA"/>
</h:selectOneRadio>

<p:outputPanel id="panelA">
    <h:selectOneMenu id="metalTypeMenuA" converter="metalConverter" value="#{backingBean.order.metal}" rendered="#{teklifIslemleriBean.selectedITip == 1}">
            <f:selectItems value="#{backingBean.metalDetailsMenu}" />
        </h:selectOneMenu>
</p:outputPanel>

backing bean:

MetalCode selectedMK = null;

public void updateMenu(AjaxBehaviorEvent event) {            

        System.out.println("Entered to updateMenu method");

        if (metal.getMetalKod()!= null) {
            electedMK = aMetal.getMetalCode();            
        }        

        if (selectedMK != null) {
            // metalTypeMenuA Combobox
            List<Metal> metalList = aService.getAccToMetalCode(null, selectedMK);
            System.out.println("MetalList:" + metalList.size());
            metalTypeMenuA.clear();
            for (Metal m : metalList) {
                metalTypeMenuA.add(new SelectItem(m, "No:" + m.getMetalNo() +  " ,Weight: " + m.getWeight();
            }
        }
    }

However it does not even enter to the updateMenu method. instead of click I tried select, change, etc. I also tried to put a wrapper panel and update it instead of checkbox, still no good. What is wrong with above code? Is updating a checkbox with a change in radiobutton doable? Thanks in advance.

JSF 2.0 Primefaces 2.2.1

EDIT: I added following

<h:message for="metalA" id="messaged"/>

<f:ajax listener="#{backingBean.updateMenu}" event="click" execute="metalKoduA" execute="metalA" render="messaged orderPG2"/> 

orderPG2 is a wrapper around checkbox. But still I can get any error message in h:message or any ajax behavior is happening.

lamostreta
  • 2,359
  • 7
  • 44
  • 61

1 Answers1

2

The render attribute of <f:ajax> should not point to a component which is by itself conditionally server-side rendered by rendered attribtue. Let it point to the closest parent which is always rendered instead.

<f:ajax listener="#{backingBean.updateMenu}" render="panelA" />

(note that I removed event="click" and execute="metalA" as those are the defaults already)

If that still doesn't work, then you'd need to read the server logs for any missing faces messages. Big change that you'll see a Validation Error: "Value is not valid" or perhaps a conversion error. To prevent those messages from being missed during ajax rendering, ensure that you're using <h:message> and/or <h:messages> the right way and that you also include them in the render of the <f:ajax>.

<h:selectOneRadio id="metalA" ...>
    ...
    <f:ajax ... render="metalAmessage panelA" />
</h:selectOneRadio>
<h:message id="metalAmessage" for="metalA" />
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • first, thanks for your detailed answer. I tried rendering a panel component which wraps checkbox, still no result. It re-renders the panel but does not even go into the method in the backing bean. I read the server logs, couldn't find any relevant log entry. I know that famous "Value is not valid" error! It costed me 2 days to find out the reason for that! :) Actually I am already using . But it does not show any error message. I will give a try to h:message. – lamostreta Feb 08 '12 at 13:33
  • I also tried h:message but nothing is happening.. (I added the code above) – lamostreta Feb 08 '12 at 14:56
  • I think there's a bug with ajax behaviour of selectoneradio. After 2 days work I change it to selectonemenu and voila! it worked like a charm. – lamostreta Feb 09 '12 at 15:14