aspose file tools*
The moose likes JSF and the fly likes How to get the managed bean property value inside the javascript method in facelets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get the managed bean property value inside the javascript method in facelets?" Watch "How to get the managed bean property value inside the javascript method in facelets?" New topic
Author

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

Ilayaraja Raju
Greenhorn

Joined: May 11, 2008
Posts: 10
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


Regards,<br />Ilaya
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bajrang Asthana
Ranch Hand

Joined: May 24, 2011
Posts: 32
I just want to make sure have you defined getHiddenCode() method in your descriptionSearch backing bean.
Ilayaraja Raju
Greenhorn

Joined: May 11, 2008
Posts: 10
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

Joined: Aug 01, 2010
Posts: 40

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"

-Abhishek
I came to this world on a Learner's License
Ilayaraja Raju
Greenhorn

Joined: May 11, 2008
Posts: 10
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

Joined: Jun 11, 2009
Posts: 8

Hi,

In your page keep a script tag


This javascript variable "hiddenCode" can be accessed in your javascript functions.
Hope it helps.


Regards,
Gerin Jacob
Lily Ju
Greenhorn

Joined: Aug 22, 2012
Posts: 1
Another example:

<a:commandButton id="hiddenButton" style="display:none" >
<a:support oncomplete="checkStatusChanged('#{manageOutstandingApprovals.listOfStatusChanged}');" event="onclick" action="#{manageOutstandingApprovals.approvalReassignAction}"/>
</a:commandButton>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the managed bean property value inside the javascript method in facelets?