You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Nuno Sousa <wi...@gmail.com> on 2008/05/24 03:46:39 UTC

Calling a bean method from an onClick event

Hello,

I have a dataTable with an HtmlInputText on each cell, i want to add
an onClick event for each inputText, so when i click on it, the values
changes to a value stored on backbean, and when i clickout the old
value comes again.
The inputText have an setOnClick(String) method, but how can i get the
bean value through a javascript function? i wanted to do something
like:

[code]dataTable.setVar("myItem");
dataTableMatriz.setValue(matriz); // ArrayList of ArrayLists

ValueBinding myItem =
FacesContext.getCurrentInstance().getApplication().createValueBinding("#{myItem.get("
+ i + ").valueX}");
            input.setValueBinding("value", myItem);

inputText.setOnClick("this.value = " + *set to a valueY just while
selected* ";");
input.setOnblur("this.value = " + *set again to valueX* ";");[/code]


Any idea how to get this?
Thanks

-- 
Ping is just a number timming is everything

Re: Calling a bean method from an onClick event

Posted by Christopher Cudennec <Sm...@gmx.net>.
Hi Nuno,

you either have to make a "submit" to your form and use a 
ValueChangeListener for your input element or use an Ajax framwork like 
Richfaces (http://www.jboss.org/jbossrichfaces/).

By the way: Your java script function seems to be missing a closing 
brace: It should be something like:

input.setOnclick("alert('#{myBackingBean.randomVar}')");

Cheers,

Christopher

Nuno Sousa schrieb:
> Thanks for your answer, but i couldn't solve my problem.
>
> I have me table defined on backbean and on my inputText if i put something like:
>
> input.setOnclick("alert('#{myBackingBean.randomVar}'");
> I get an alert with the message: #{myBackingBean.randomVar}
>
> If i remove the ' ' before and after #{myBackingBean.randomVar}
> It gives me an javascript error, saying me that it's not defined or something
>
> Any ideas?
>
>
>
> On Sat, May 24, 2008 at 3:19 AM, Mike Kienenberger <mk...@gmail.com> wrote:
>   
>> I've passed el expressions into a function like this on my page code.
>> I'm using facelets, but I don't think it makes any difference.
>>
>>                                                          rowOnClick="colorizeRow('#{routeSplitReorderPage.routeTableDataOne.uiDataClientId}',
>> '#{routeSplitReorderPage.routeTableDataOne.selectedRowInputClientId}',
>> this.id, '#{rowIndex}');"
>>
>> For more detail:
>>
>> http://www.mail-archive.com/users@myfaces.apache.org/msg35159.html
>>
>> If you don't like that approach for some reason, take a look at the
>> thread named "How to get value from managed bean by JavaScript" from
>> April 2007 -- there's a number of other approaches mentioned in
>> response to that question.
>>
>> http://mail-archives.apache.org/mod_mbox/myfaces-users/200704.mbox/%3c5F3FE6FFFCC6C04FB1D74825AFE2E091B1F7C3@venus.sybit.de%3e
>>
>>
>> On Fri, May 23, 2008 at 9:46 PM, Nuno Sousa <wi...@gmail.com> wrote:
>>     
>>> Hello,
>>>
>>> I have a dataTable with an HtmlInputText on each cell, i want to add
>>> an onClick event for each inputText, so when i click on it, the values
>>> changes to a value stored on backbean, and when i clickout the old
>>> value comes again.
>>> The inputText have an setOnClick(String) method, but how can i get the
>>> bean value through a javascript function? i wanted to do something
>>> like:
>>>
>>> [code]dataTable.setVar("myItem");
>>> dataTableMatriz.setValue(matriz); // ArrayList of ArrayLists
>>>
>>> ValueBinding myItem =
>>> FacesContext.getCurrentInstance().getApplication().createValueBinding("#{myItem.get("
>>> + i + ").valueX}");
>>>            input.setValueBinding("value", myItem);
>>>
>>> inputText.setOnClick("this.value = " + *set to a valueY just while
>>> selected* ";");
>>> input.setOnblur("this.value = " + *set again to valueX* ";");[/code]
>>>
>>>
>>> Any idea how to get this?
>>> Thanks
>>>
>>> --
>>> Ping is just a number timming is everything
>>>
>>>       
>
>
>
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 8.0.100 / Virus Database: 269.24.1/1466 - Release Date: 25.05.2008 18:49
>   


Re: Calling a bean method from an onClick event

Posted by Nuno Sousa <wi...@gmail.com>.
Thanks for your answer, but i couldn't solve my problem.

I have me table defined on backbean and on my inputText if i put something like:

input.setOnclick("alert('#{myBackingBean.randomVar}'");
I get an alert with the message: #{myBackingBean.randomVar}

If i remove the ' ' before and after #{myBackingBean.randomVar}
It gives me an javascript error, saying me that it's not defined or something

Any ideas?



On Sat, May 24, 2008 at 3:19 AM, Mike Kienenberger <mk...@gmail.com> wrote:
> I've passed el expressions into a function like this on my page code.
> I'm using facelets, but I don't think it makes any difference.
>
>                                                          rowOnClick="colorizeRow('#{routeSplitReorderPage.routeTableDataOne.uiDataClientId}',
> '#{routeSplitReorderPage.routeTableDataOne.selectedRowInputClientId}',
> this.id, '#{rowIndex}');"
>
> For more detail:
>
> http://www.mail-archive.com/users@myfaces.apache.org/msg35159.html
>
> If you don't like that approach for some reason, take a look at the
> thread named "How to get value from managed bean by JavaScript" from
> April 2007 -- there's a number of other approaches mentioned in
> response to that question.
>
> http://mail-archives.apache.org/mod_mbox/myfaces-users/200704.mbox/%3c5F3FE6FFFCC6C04FB1D74825AFE2E091B1F7C3@venus.sybit.de%3e
>
>
> On Fri, May 23, 2008 at 9:46 PM, Nuno Sousa <wi...@gmail.com> wrote:
>> Hello,
>>
>> I have a dataTable with an HtmlInputText on each cell, i want to add
>> an onClick event for each inputText, so when i click on it, the values
>> changes to a value stored on backbean, and when i clickout the old
>> value comes again.
>> The inputText have an setOnClick(String) method, but how can i get the
>> bean value through a javascript function? i wanted to do something
>> like:
>>
>> [code]dataTable.setVar("myItem");
>> dataTableMatriz.setValue(matriz); // ArrayList of ArrayLists
>>
>> ValueBinding myItem =
>> FacesContext.getCurrentInstance().getApplication().createValueBinding("#{myItem.get("
>> + i + ").valueX}");
>>            input.setValueBinding("value", myItem);
>>
>> inputText.setOnClick("this.value = " + *set to a valueY just while
>> selected* ";");
>> input.setOnblur("this.value = " + *set again to valueX* ";");[/code]
>>
>>
>> Any idea how to get this?
>> Thanks
>>
>> --
>> Ping is just a number timming is everything
>>
>



-- 
Ping is just a number timming is everything

Re: Calling a bean method from an onClick event

Posted by Mike Kienenberger <mk...@gmail.com>.
I've passed el expressions into a function like this on my page code.
I'm using facelets, but I don't think it makes any difference.

							  rowOnClick="colorizeRow('#{routeSplitReorderPage.routeTableDataOne.uiDataClientId}',
'#{routeSplitReorderPage.routeTableDataOne.selectedRowInputClientId}',
this.id, '#{rowIndex}');"

For more detail:

http://www.mail-archive.com/users@myfaces.apache.org/msg35159.html

If you don't like that approach for some reason, take a look at the
thread named "How to get value from managed bean by JavaScript" from
April 2007 -- there's a number of other approaches mentioned in
response to that question.

http://mail-archives.apache.org/mod_mbox/myfaces-users/200704.mbox/%3c5F3FE6FFFCC6C04FB1D74825AFE2E091B1F7C3@venus.sybit.de%3e


On Fri, May 23, 2008 at 9:46 PM, Nuno Sousa <wi...@gmail.com> wrote:
> Hello,
>
> I have a dataTable with an HtmlInputText on each cell, i want to add
> an onClick event for each inputText, so when i click on it, the values
> changes to a value stored on backbean, and when i clickout the old
> value comes again.
> The inputText have an setOnClick(String) method, but how can i get the
> bean value through a javascript function? i wanted to do something
> like:
>
> [code]dataTable.setVar("myItem");
> dataTableMatriz.setValue(matriz); // ArrayList of ArrayLists
>
> ValueBinding myItem =
> FacesContext.getCurrentInstance().getApplication().createValueBinding("#{myItem.get("
> + i + ").valueX}");
>            input.setValueBinding("value", myItem);
>
> inputText.setOnClick("this.value = " + *set to a valueY just while
> selected* ";");
> input.setOnblur("this.value = " + *set again to valueX* ";");[/code]
>
>
> Any idea how to get this?
> Thanks
>
> --
> Ping is just a number timming is everything
>