Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the managed bean property value inside the javascript method in facelets?

 
Ilayaraja Raju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gurus,

Can anyone tell me how to get the managed bean property value inside the javascript method

something like

function showMainCat(){
var hidCode = "#{descriptionSearch.hiddenCode}";
}

I cannot get the hiddenCode property of descriptionSearch managed bean in this.

Can anyone help me to let me know how to get this value inside javascript method

Thanks.
Regards,
Ilaya
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you place that JavaScript snippet on your page (View) definition inside "f:verbatim" tags, the value of that property will be substituted into the generated HTML when the page loads. If that's an input field, it will not reflect any changes the user makes, because the EL is evaluated before the page displays and is not re-evaluated.

To get the current value of an input field, you'd have to look at the generated HTML for the input control in question and code your JavaScript to rip out the current value by brute force from the raw HTML. Helpful hint: make sure that the target control and its containers all have explicit IDs, since the auto-generated IDs tend to wander around a bit.
 
Bajrang Asthana
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to make sure have you defined getHiddenCode() method in your descriptionSearch backing bean.
 
Ilayaraja Raju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bajrang asthana wrote:I just want to make sure have you defined getHiddenCode() method in your descriptionSearch backing bean.


Hi Bajrang,

Thanks for your comment. I have getHiddenCode() method in the controller (DescriptionSearch.java).

My problem is I donno how to get the value of descriptionSearch.hiddenCode in the javascript in the xhtml page.

Thanks & Regards,
Ilaya
 
Abhishek Ralhan
Ranch Hand
Posts: 40
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can use a hidden field like:
<input type="hidden" id="test" value="#{backBean.value}"> in your page.
And in your javascript you can getElementId("test") and read its value.

Note: I don't remember the "input type hidden" for jsf , hence i used the jsp component "input"
 
Ilayaraja Raju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Ralhan wrote:Hi,

You can use a hidden field like:
<input type="hidden" id="test" value="#{backBean.value}"> in your page.
And in your javascript you can getElementId("test") and read its value.

Note: I don't remember the "input type hidden" for jsf , hence i used the jsp component "input"


Thanks Abhishek.

Actually I tried this option. The problem associated here is the id of the element is dynamically generated by jsf. so i cannot get the value of the element.

Is there anyway to fetch the backbean value from the javascript ( as we do in the jsp).

Regards,
Ilaya
 
Gerin Jacob
Greenhorn
Posts: 8
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In your page keep a script tag


This javascript variable "hiddenCode" can be accessed in your javascript functions.
Hope it helps.
 
Lily Ju
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another example:

<a:commandButton id="hiddenButton" style="display:none" >
<a:support oncomplete="checkStatusChanged('#{manageOutstandingApprovals.listOfStatusChanged}');" event="onclick" action="#{manageOutstandingApprovals.approvalReassignAction}"/>
</a:commandButton>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic