participate


JavaServer Faces - how to call a bean method through javascript?
<<   Back to Forum  |   Give us Feedback
This topic has 3 replies on 1 page.
actmortage
Posts:61
Registered: 2/2/06
how to call a bean method through javascript?   
Feb 13, 2006 7:46 AM

 
Hi,

i want to call a bean method using the javascript.

thansk in advance.
 
Semmerle
Posts:60
Registered: 9/6/05
Re: how to call a bean method through javascript?   
Feb 13, 2006 8:34 AM (reply 1 of 3)  (In reply to original post )

 
Please be more specific and tell you why and where you want to call a backing bean from javascript
 
actmortage
Posts:61
Registered: 2/2/06
Re: how to call a bean method through javascript?   
Feb 13, 2006 9:57 AM (reply 2 of 3)  (In reply to #1 )

 
hi

i want to call a backing bean method thought javscript on the button click.

i am inplementing addition of textbox at runtime.i wrote method and i am calling that on the button click.but the textbox is not created.

the code is bleow

public String doAction() {
tryStuff1();
return "samplejsf";
}

public void tryStuff1()
{
System.out.println("Enter the trystuff method");
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot uIViewRoot = facesContext.getViewRoot();
Application application = facesContext.getApplication();
UIComponent formComp=uIViewRoot.findComponent("subbody:form1");
HtmlPanelGrid grid= new HtmlPanelGrid();
grid.setId("panelgrid2");
grid.setColumns(2);
grid.setBorder(2);
//UIComponent panelGridComp=formComp.findComponent("subbody:panelgrid1");
//UIComponent panelGroupComp=panelGridComp.findComponent("panelgroup2");

HtmlOutputText output = new HtmlOutputText();
output.setValue("dynamic jsf text2");
System.out.println("hello output text2");
output.setRendered(true);
grid.getChildren().add(output);

HtmlInputText input = new HtmlInputText();
input.setSize(40);
input.setValueBinding("value", (ValueBinding) application.createValueBinding("#{sample.text2}"));
input.setRendered(true);
grid.getChildren().add(input);

System.out.println("hello output text1");
grid.setRendered(true);
formComp.getChildren().add(grid);
System.out.println("hello output text3:");
formComp.getRendersChildren();
formComp.setRendered(true);

}

public boolean getRendersChildren() {
return true;
}

jsp code is


<h:form id="form1">

<h:panelGrid columns="2" binding="#{sample.formElements}">
</h:panelGrid>



<h:panelGrid id="panelgrid1" columns="1">
<h:panelGroup id="panelgroup1">
<h:outputText value="hardcoded jsf text1"/>
<h:inputText value="#{sample.text1}"/>
</h:panelGroup>

</h:panelGrid>
<h:commandButton id="add" action="#{sample.doAction}" value="add" type="SUBMIT"/>
</h:form>


when i click on the button its going into the method and diaplying s.o.p but the text box is not updated to the page.

why is it so.
i thought there may be a problem in calling the method directly thru button. i want to try thru javascript calling the bean method.

why is the page not updated.
can u help me out

thanks in advance
sree
 
jsfnoah
Posts:10
Registered: 1/26/06
Re: how to call a bean method through javascript?   
Feb 13, 2006 2:32 PM (reply 3 of 3)  (In reply to #2 )

 
Here is how we are doing this:

Our button looks like this:
<h:commandButton id="id" onclick="doSomething()" />

Our JavaScript looks like this:
function doSomething()
{
    // Do some javascript stuff here 
    //...
 
    // get reference to our hidden command link to fire a backing bean method
    var hiddenCommandLink = window.document.getElementById("pageForm:cl1");
    	if (hiddenCommandLink )
	{
		hiddenCommandLink .fireEvent("onclick");
	}
}	


Our hidden commandLink that calls the backing bean method looks like this:

<h:commandLink action="#{backingBean.doSomething}" id="cl1" style="display: none" />
 
This topic has 3 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 63
  • Guests : 118

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums