简体   繁体   中英

JSF h:inputHidden managed bean value not updated in ajax call

I have a h:inputHidden field where it's value needs to be updated by an ajax call. I tried to use an f:ajax tag in the h:inputHidden element but it didnt work (gave an error saying that you cannot used <f:ajax> in h:inputHidden tag).

<h:panelGroup id="datesSelectPanel" styleClass="form-group">
  <div class="col-md-8">
    <div id="dateSelector" class="col-md-4"></div>
      <div class="col-md-offset-1 col-md-1">
        <h:commandLink id="selectedDates" styleClass="btn default" style="margin: 90px 0 0 0;">
         <i class="fa fa-forward"></i>
         <p:ajax process="pickerHiddenPanel" onstart="loadSelectedDates()"/>
        </h:commandLink>
    </div>
    <h:panelGroup id="dateSelectPanel" class="col-md-4">
      <h:panelGroup id="pickerHiddenPanel" styleClass="ulSelectedDatesHidden">
        <h:inputText id="sDates" value="#{managedBean.selectedDates}" style="display:none;" />
      </h:panelGroup>
      <ul style="width: 150px; height: 220px;" class="pull-left" id="ulSelectedDates"></ul>

DOM element ids

  1. dateSelector - Is a multi date picker
  2. selectedDates - Is a button that populates a list ulSelectedDates via javascript
  3. sDates - Is the hidden filed that is supposed to store the date picker values to the managed bean.

So this is what happens, I select multiple dates from a multi date picker (Bootstrap), and click a button to populate a box next to the calendar. When that is done the #{managedBean.selectedDates} bean value isnt updated as expected. I use Javascript to populate the list using function loadSelectedDates() which adds <li> elements to the <ul> .

I need to capture the date selection in the managed bean. Is there a way to solve this? Appreciate the help.

PS : I used an h:inputText as suggested in another post that also didn't work, that is why you are seeing h:inputText rather than h:inputHidden

Based on posted code:

  • You didn't populate the value of <h:inputText id="sDates"/> in DOM
  • ConverterException is thrown when converting value of <h:inputText id="sDates"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM