Update SelectOneMenu if value of ohter SelectOneMenu is set (Event isn't fired)

回眸只為那壹抹淺笑 提交于 2019-12-12 10:54:38

问题


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();
}

回答1:


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}"/>


来源:https://stackoverflow.com/questions/12641409/update-selectonemenu-if-value-of-ohter-selectonemenu-is-set-event-isnt-fired

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!