5

In my application I'm trying to set/update a SelectOneMenu if another SelectOneMenu is set. We're using primefaces, so I checked the primefaces showcase and found exactly what I was looking for. Unfortunately it's not working. The Event isn't fired and I don't know why. Hopefully you can help me

Link to the Example of the primefaces showcase

-> If the language is set, it should automatically reload the list with the salutations, but it doesn't. I have to press F5 to reload. Any ideas?

My xhtml code

<h:form id="addressBasicsForm">
  <p:growl id="growl" sticky="true" showDetail="true"/>
  <p:tabView id="tabView">
    <p:tab id="stammdaten" title="#{msg.adr_basics_tabtitle}">
  <table style="width:100%;">
        <tr>
          <td style="width: 50%;">
    <p:panel toggleable="false">
      <table style="margin-top:3px; width:100%;">
        <tr style="height:26px;">
          <td>
            <p:selectOneMenu id="somLang" value="#AddressBasics_m.languageId}" style="margin-left:2px; width:90%;">
              <f:selectItems value="#{AddressBasics_m.languageItems}"/>
                      <p:ajax update="somAnrede" listener="#{AdressBasics_m.handleLanguageChange}"/>
            </p:selectOneMenu>
          </td>
        </tr>
        <tr style="height:26px;">
          <td>
            <p:selectOneMenu id="somAnrede" value="#AddressBasics_m.salutationId}" style="margin-left:2px; width:90%;">
              <f:selectItems value="#{AddressBasics_m.salutationItems}" />
            </p:selectOneMenu>
          </td>

My Bean

@Named("AddressBasics_m")
@ConversationScoped
public class AddressBasicsView implements Serializable{
private static final long serialVersionUID = -4034697810438325785L;

public List<SelectItem> getSalutationItems(){
    if(firstrun)
        languageId = 21L;

    firstrun = false;
    if(salutationItems == null || lastLanguageId != languageId){
        salutationItems = addressService.getAllSalutationsByLangId(languageId);
        setLastLanguageId(languageId);
    }
    return salutationItems;
}

public void handleLanguageChange(){
    this.salutationItems = getSalutationItems();
}
Raphael_S
  • 152
  • 2
  • 3
  • 13
  • Did you verify that another component in that form is not throwing a validation error? – maple_shaft Sep 28 '12 at 14:29
  • Yes i checked that. No validation errors thrown – Raphael_S Oct 03 '12 at 06:06
  • 1
    1. Html code in your xhtml 2. Single line if without curly brackets 3. Bussiness logic in your getter. 4. An action listener method without ActionEvent (wrong signature). 5. Posting Only part of your xhtml. 6. Using Named instead of ManagedBean 7. Using ConversationScoped instead of ViewScoped 8. Finally your getter looks like an actionListener and your actionListener looks like a setter. These are plain wrong or not recommended – Kerem Baydoğan Oct 11 '12 at 08:13

1 Answers1

2

I believe that the problem is on your Ajax call. Ajax could be very tricky, I would recommend 2 different approachs:

<p:ajax render="@form" listener="#{AdressBasics_m.handleLanguageChange}"/>

or

<p:ajax update=":addressBasicsForm:tabView:stammdaten:somAnrede" listener="#{AdressBasics_m.handleLanguageChange}"/>
TalesTk
  • 181
  • 3