Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

h:command button not firing through java script  RSS feed

 
Vinodh Sa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I m facing a problem while firing a hidden button through javascript.

function submitCountryID(countryID)
{
document.getElementById("subViewID:formID:textFieldID").value = countryID;
alert('hi called');
document.getElementById("subViewID:formID:cmdBtnID").click();
}

<f:subview id="subViewID">
<h:form style="margin:0px" id="formID">
<h:panelGroup>
<h:commandButton id="cmdBtnID" action="#{javaBean.submitVinodh}" value="Submit"/>
<h:inputHidden id="textFieldID" value="#{javaBean.countryIDVal}"/>
</h:panelGroup>
</h:form>
</f:subview>

when i call this java script, i m getting the alert msg, but the button which i m firing in the next line is not getting fired.
Can someone explain me why ? (In my observation, it seems like the entire form is getting resubmitted)
Inside the action method of that command button, i m intentionally creating a null pointer exception, but i m not getting that error, since the method is not called.

 
Victor Hugo M Machado
Greenhorn
Posts: 22
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see the source code of your JSP.. see the HTML generated..
hidden components not are rendered

I hope understood your problem
 
Vinodh Sa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Hugo M Machado wrote:see the source code of your JSP.. see the HTML generated..
hidden components not are rendered

I hope understood your problem


No Dude.... If you notice clearly that command button is currently not hidden... And also they are generated in the HTML of my page..... Seems to be like some other servlet is getting called.... Can you know abt how to stop all other calls (to servlets) while firing this button....?
 
Victor Hugo M Machado
Greenhorn
Posts: 22
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF LifeCycle
I think is the same servlet who call every calls of this methods..


my english is really bad and I have some difficult to understand what you saying
sorry
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vinodh.

I'm not sure if the click javascript function makes a postback, but I think it don't send the correct parameters that need the request process lifeycle to identify the component that launches the request and so process the action method of the component .

I'll give you a clue how to solve your problem, when you use a h:commandLink you can see in the generate page markup (when you choose see view source from your browser) that produce a <a> tag with a javascript function for onclick event, that function you can use to make a correct postbak from your submitCountryID javascript function, in my case I'm using JSF 2.0 and the function is so:

Regards

Cesar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!