This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes Calling JSF bound method via javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Calling JSF bound method via javascript" Watch "Calling JSF bound method via javascript" New topic
Author

Calling JSF bound method via javascript

Don Cracker
Greenhorn

Joined: Feb 21, 2010
Posts: 3
Hi

I am trying to invoke a commandButton with an action (i.e. invoke a bound method on a backing bean) from javascript. I am doing this because the method binding will not work if I place the <h:commandButton> tag within a jQuery component.

So, within my jQuery component (a modal dialog) I have an anchor that initiates the JS method:


And outside the jQuery element, I define a hidden JSF commandButton:


Now the important part - the javascript:

defaultForm is the id of my JSF <h:form>.

The alert method is invoked, and displays an object reference... BUT the click() on the object just NEVER manages to work... i.e. the bound backing bean method never ever gets reached.
Any suggestions? I've tried making the anchor a commandButton with onclick defined - but that has the same result. I am using JSF 1.2 (project conrestraint).
Any help would be very greatly appreciated.
Joe ONeil
Greenhorn

Joined: Jan 16, 2009
Posts: 12
function callbutton(){
document.getElementById("Frm1" + ":vendbtn").click();
}

if you want to make the button invisible you can do this

<h:form id="Frm1">

<t:commandButton id="vendbtn" value="" action="#{poDetail.loadVendorAddresses}" immediate="true"
style="visibility:hidden;" />
</h:form>
immediate ="true // skip validation and you will not beable to pick up values from the page
the style hides the button and there is no tab location
 
Don't get me started about those stupid light bulbs.
 
subject: Calling JSF bound method via javascript