• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem using valueChangeListener and onchange

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am having some troubles with JSF. I have a page that has a selectOneListbox in it. What I want to have happen is that when the user picks an item in the listbox, the page will execute a method in our listener class. What is happening is that the page gets reloaded, but the listener method is not being fired off. My JSF code is:

<h:form>
<f:verbatim>
<TABLE>
<TR>
<TD>
<B><h:outputText value="Field Name: "/></B>
</TD>
<TD>
<h:selectOneListbox id="uiSelectionField" size="1"
valueChangeListener="#{projectListener.uiInitialSelect}"
onchange="this.form.submit()" immediate="true">
<f:selectItem itemValue="Environment" itemLabel="Environment"/>
<f:selectItem itemValue="Status" itemLabel="Status"/>
<f:selectItem itemValue="Priority" itemLabel="Priority"/>
<f:selectItem itemValue="Release" itemLabel="Release"/>
<f:selectItem itemValue="Issue Type" itemLabel="Issue Type"/>
<f:selectItem itemValue="Function" itemLabel="Function"/>
<f:selectItem itemValue="Module" itemLabel="Module"/>
</h:selectOneListbox>
</TD>
</TR>
</TABLE>
</f:verbatim>
</h:form>

What are we doing wrong?

Thanks.
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about the repost, I got some kind of error trying to post and thought the post hadn't gone through.
[ September 13, 2007: Message edited by: Ian Dunsirn ]
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont see anything obviously wrong with the given code. Can you elaborate on how do you determine that the valueChangeListener is not notified or the method in your backing bean in not getting called..?
Are you getting any error message or you cant see the expected behaviour in your page while you submit - please explain or if required provide backing bean code as well.
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I put in some displays in the method I am invoking and I do not see it when I look at my console in Eclipse. I see displays that are in other methods, but not that one. I am not at work and can't put up that code at the moment.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ian
if possible post the error message..so that i can go thru and provide you the solution

Hedzar
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And there is the rub. We are not getting any error messages at all. I even misspelled the name of the invoked method on purpose to get an error. Nothing. The page does reload, but none of the displays we put in are showing up. We are newbs and at a loss as to what we may be missing.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see the "value" attribute in your h:select...Could it be it?
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was under the impression that value would be needed only if we were populating the listbox with data from a table. If I am incorrect, let me know.
 
A. Dusi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the f:verbatim tag that's causing the problem.
I tested your code after removing that tag and it worked fine for me. Try not to include your component under that. f:verbatim's purpose is different...see the documentation.

Regarding the page reload its only because you are using javascript onchange and submit and is not part of your JSF actions.

And you were right that value attribute is not needed just to call the valueChangeListener. However if you want to capture the selected value, you do need it.
[ September 14, 2007: Message edited by: A. Dusi ]
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, do I need the onchange=submit then?
 
A. Dusi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are only looking to capture your listbox selection, you dont need the valueChangeListener.
Simply provide the value attribute mapping to a backing bean's property of String type(your itemValues are Strings). On form submission(by a click of a button or onchange=submit), the selection will automatically be posted to your backing bean's property.

Note that the form submission using javascript onchange=submit is useful only if there are other components on your page that need to be populated dynamically based on your listbox selection. In all other cases, a simple button submit will do.
By using javascript onchange=submit, you make the selected value post to your backing bean immediately.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Funny, I just did this last week. OK, so if you want a valueChangeListener to say change the values in a DataTable or in another combobox, there are a couple of things that you will need.

1. There are two ways to declare your valueChangeListener. One is the a <valueChangeListener> tag which requires a fully qualified class name, and that Class must implement the ValueChangeListener interface. The other, which is what I am going to talk about is the valueChangeListener attribute for any UIInput tag, which has the EL link to a method in a backing bean.

OK, so for the attribute.

set the EL to the method. Also set an onChange attribute to == "submit()" you most likely will want immediate="true" also in that tag.

In your method code, at the end of the code you will want to do the method call to go directly to the renderPhase, so something like FacesContext.getInstance.renderPhase() I forgot the last method name, but it should be easy enough to find.

Mark
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone! im new around here, and as i was looking for a solution to the problem im facing during my jsf development, i've found this post. Almost explained what should i do to solve it. Im facing the same problem, my valueChangeListener is not called any time! i wrote some sysout line codes to catch it on eclipse console, but nothing happens .

Im trying to find out what is the difference


the structure is showed below:

##index.jsp##


## newBridgeInputForm.jsp ##


## managedBean ##



As you can see, the XinputForm.jsp is loaded based on the item chosen in the first <h:selectOneMenu>. In this case im not using any <f:verbatim> tag, and it just refuse to work properly

Help me, please!

Thanks anyway!
 
reply
    Bookmark Topic Watch Topic
  • New Topic