You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by sj...@stradefi.com on 2006/03/03 23:38:47 UTC
bean call in jsp
Hi!
I am looking to call a function from my bean into my jsp page.
For example:
- Bean class: Users
- Bean class: X
- in this class X I have the function: getHobbies(username)
- in my jsp page I get all users nodes and I want to display each user with
the list of his hobbies thanks to this function getHobbies, please would you
mind telling me if it is possible? I was thinking of something like this:
<a:richList id="users-list" binding="#{UsersBean.usersRichList}"
viewMode="details" pageSize="10"
styleClass="recordSet" headerStyleClass="recordSetHeader"
rowStyleClass="recordSetRow" altRowStyleClass="recordSetRowAlt" width="100%"
value="#{Users.users}" var="b" initialSortColumn="userName"
initialSortDescending="true">
<h:selectOneMenu id="hobbies" style="width:150px" >
<f:selectItems actionListener="#{X.getHobbies(b.username}" />
-->how to call the function
here
</h:selectOneMenu>
Thanks
Best
Sophie
Re: bean call in jsp
Posted by Mike Kienenberger <mk...@gmail.com>.
It's not possible to call methods with functions in JSF EL, but you
should be able to use #{X.hobbyMethod}
and then use
public void hobbyMethod(ActionEvent e)
{
b = UsersBean.getUsersRichList().getRowData();
...b.username.....
}
in your java code.
UsersBean.getUsersRichList() returns a UIData, not a List, by the way.
I still don't think this will do what you want as this isn't the
correct way to initialize a selectOneMenu.
Instead, you should create a getHobbies() method which returns a
SelectItems[] array. In it, you'd iterate over your #{Users.users}
list, assigning the b.hobbies value to each label, and b as the
SelectItem value.
You might need or want to create a HobbyConverter (assuming Hobby is
the data type of B).
On 3/3/06, sjarlier@stradefi.com <sj...@stradefi.com> wrote:
> Hi!
>
> I am looking to call a function from my bean into my jsp page.
> For example:
> - Bean class: Users
> - Bean class: X
> - in this class X I have the function: getHobbies(username)
> - in my jsp page I get all users nodes and I want to display each user with
> the list of his hobbies thanks to this function getHobbies, please would you
> mind telling me if it is possible? I was thinking of something like this:
>
> <a:richList id="users-list" binding="#{UsersBean.usersRichList}"
> viewMode="details" pageSize="10"
> styleClass="recordSet" headerStyleClass="recordSetHeader"
> rowStyleClass="recordSetRow" altRowStyleClass="recordSetRowAlt" width="100%"
> value="#{Users.users}" var="b" initialSortColumn="userName"
> initialSortDescending="true">
>
> <h:selectOneMenu id="hobbies" style="width:150px" >
> <f:selectItems actionListener="#{X.getHobbies(b.username}" />
> -->how to call the function
> here
> </h:selectOneMenu>
>
> Thanks
> Best
> Sophie
>
>