views:

150

answers:

1

Hi all!

On selecting a DIV element, i take the value of the selected DIV's hidden element and pass it on to a form with hidden element in it. This form is then submitted. Below are pieces of my code.

The value of the hidden input inside the form is correctly set on selecting the DIV and the form is also submitted but the valueChangeListener is not fired.

Every hint is welcome!

-choesang

Form with hidden element:

<a4j:form id="currentForumPost" ajaxSubmit="true" 
          onsubmit="console.log('currentForumPost is submitted'); 
          console.log(jQuery('#currentForumPost:currentPostId').val())" >
       <h:inputHidden id="currentPostId" 
       valueChangeListener="#{forumController.changeListenerSelectedForumPost}" 
       immediate="true"/>
</a4j:form>

DIV element:

<div class="block ui-accordion ui-widget ui-helper-reset"  
  onclick="var x = jQuery(this).find('.hiddenInputText').val();        
  jQuery(this).closest('#RightPane').find('#currentForumPost:currentPostId').val(x);      
  jQuery(this).closest('#RightPane').find('#currentForumPost').submit();">
  <h:inputText value="#{post.uuid}" styleClass="hiddenInputText"/>
                      ......
</div>

Java

public void changeListenerSelectedForumPost(final ValueChangeEvent event) {
setSelectedForumPost(event.getComponent().getAttributes().get("value").toString());  

}

+1  A: 

It appears that you do not have a valueChangeListener attribute on the inputText. You need this attribute so JSF knows which listener to call. Assuming your bean is named 'bean', here is an example:

<h:inputText value="#{post.uuid}" valueChangeListener="#{bean.changeListenerSelectedForumPost}" styleClass="hiddenInputText" />
Colin Gislason
Hi Colin, Thanks for answering my post. Part of my code was not visible, sorry about that. I do have a valueChangeListener, not exactly for the element <h:inputText> but for <h:inputHidden>. Please note that, <h:inputHidden> is the element submitted to the server side.
tchoesang
Ok. Nothing looks obviously wrong now. Does it work if you change the h:inputHidden to an h:inputText?
Colin Gislason