Setting parameter value for binding with code

Back in the 10.1.3 days I wrote an entry that showed how to set the value of a parameter that is referenced in your page's binding by writing some code in your backing bean.
Well with 11g we moved to JSF 1.2 and things have changed a bit.
And today I needed to look up the update syntax for a demo I was working on.

Since this is a useful little piece of code I'm pasting it here for my own future reference.
A special shout out to Edwin Biemond for this post that has a lot of other useful code bits.
If you want more of these download the Fusion Order demo and look up the JSFUtil java class that is used throughout the demo when coding in the backing bean is needed.

[code]
FacesContext facesCtx = FacesContext.getCurrentInstance();
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesCtx.getELContext();
ValueExpression ve =
elFactory.createValueExpression(elContext, "#{bindings.p_zip.inputValue}",
Object.class);
ve.setValue(elContext, newValue);
[/code]

Comments:

Hi Shay,

This really doesn't work for me - and I've now tried both the old way and the new way (with 11g). My web service request works, but I have to forcibly type the word "true" into an input box or my call simply doesn't contain the 'main="true"' component in my web service SOAP request which is essential for the service to respond with success.
I've even tried hard-coding the value of the text-box to true and that still doesn't give me the required functionality and I can't expect my users to randomly enter 'true' in a text box just to use a web service. Would it help if I sent a video to describe my problem?

Any help gratefully appreciated.

Many thanks,
Darren

Posted by Darren on August 31, 2011 at 06:36 PM PDT #

Darren, I would suggest that you try and debug your code as it runs and see where it fails.
Also - have a look at your binding tab for the page and locate the parameter - if you just need it to be "true" then you can hard code the value for the parameter in the binding tab.

Posted by Shay on September 01, 2011 at 04:32 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

me
I'm a Director of Product Management for the Oracle Java Development Tools.
Follow me:
Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today