• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

af:selectOneChoice - setting default selected value other than the first in line

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm, I'm stuck and would appreciate any help available (bet you've never read that on here before - LOL).

I'm building a dynamically populated af:selectonechoice and it works almost exactly as I'd like it. I'm grabbing distinct years from our database for those records which are active via a query in a sessionfacadebean - this query simply orders them in decending order (for example: 2011, 2010, 2009, 2008). But, my problem is that I can only get the page to load with the selectonechoice defaulted to the first year in the list.

Here's the code as it sits now . . .

jspx page:


and here's the code from the backing bean:




I've tried any and all manner of voodoo and code permutations, but, obviously, I'm missing the obvious somewhere. The selectoncechoice ALWAYS defaults to whatever the first year in the resultset is - and, of course, we want the years in order. But, we'd like the page to load with the current year selected by default.

So, the list may be:
2010
2009
2008

We'd like 2009 to be the default selected, not 2010 - which is what's being selected now (since it's first in the list).

* I've tried setting a value of "holder" in the backing bean when I'm working with the current year, and then reference that in the jspx page with the "value" element of the af:selectOneChoice - like this --> value="#{backing_reports_calholiday.holder}" . . . but, that didn't work.
* I can, of course, hard code the "value" element of the af:selectOneChoice when I "know" what the placement of the current year is in my result set . . . but, obviously, that's not the solution.

In my old .asp days it would simply be dynamically setting one of the <option> tags as "selected" within the <select> tag.

Hmmm (Image of me scratching my chin thoughtfully)

Any and all help would be greatly appreciated.



d
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on beginning Java.

For more information, please read this.

This post has been moved to a more appropriate forum.
 
Dan Ba
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Please take the time to choose the correct forum for your posts. This forum is for questions on beginning Java.

For more information, please read this.

This post has been moved to a more appropriate forum.



Sorry, not trying to cause trouble.

But, I am just beginning java.

Again, sorry.



Dan-O
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's already been moved to the JSF forum.
 
Dan Ba
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, tried a change and it's now presenting me with a different problem.

I changed my if statement in the backing bean.
I had (see line 15):



The problem (I think) is that 'year' is a Long and 'currentyear' is an Integer. So, I was getting a false. I changed it to (again, see line 15):



And, then, I removed the hard coded set of the value from the .jspx and then the page loaded correctly.

Unfortunately, now when I (as a user) choose a different option from the selectOneChoice list box . . . the page refreshes with the value set in the backing bean (in this instance, the current year).

grrrrrrr.



Dan-O
 
Dan Ba
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wanted to close any loose ends here (in case it might help others).

I changed the if statement below to only set the value based upon whether the page was a postback or an initial load. As follows:

I added this method (introduced to me by a co-worker) to the backing bean:


Then changed the if statement with the setValue as follows:
(see line 15):



page works as desired now.

Thanks for traveling along with me on my little quest for knowledge.


Dan-O
 
reply
    Bookmark Topic Watch Topic
  • New Topic