• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 23729
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 40
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 8
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
reply
    Bookmark Topic Watch Topic
  • New Topic