• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

h:command button not firing through java script

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Greenhorn
Posts: 22
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 90
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 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic