You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Anton Gavazuk <an...@gmail.com> on 2008/08/20 10:33:08 UTC

Composite view from several "request" managed beans

Hi all,

have maybe a silly question

if I need to show a page which consists from several parts (modules)
with different info, and this info cannot be stored in session beans,
it should be refreshed on every request, so there is need for several
managed beans with request scope.

So if request forwards on such "composite"  page, should I create and
put this beans in context manually in an JSF method or there is
another way how to achieve this?

Many thanks,
Anton

Character Encoding Problem

Posted by Enrico Drusiani <ed...@zensistemi.com>.
Hi Everyone

i'm using MyFaces implementation 1.1.5 on jboss 4.2.2 and seam 1.2. I'm 
having a problem in showing proper characters in ajax comboboxes.

The code is

xmlns:sa="http://myfaces.apache.org/sandbox"
...
<sa:inputSuggestAjax charset="iso-8859-15" id="#myID" 
suggestedItemsMethod="#{myclass.getSuggestItems}" />

instead of "è" i'm getting &#232; I've checked on both db and code, and 
it goes correctly until this ajax call. Any suggestion?

Thanks for your time

Enrico Drusiani




Re: Composite view from several "request" managed beans

Posted by Anton Gavazuk <an...@gmail.com>.
Also can be possible to use for complex page compositor class as
managed bean - include in Compositor managed bean (Dashboard) others
managed beans.
Looks like I will prefere this, if anyone dont provide better idea

2008/8/20 Anton Gavazuk <an...@gmail.com>:
> Ok, somehow out of scope but
>
> very popular topic :) - send an parameter (for example in CRUD - send
> an ID from list to view/edit screen)
>
> my approach:
>
> ManagedBean has getter for list and particular class field for list
>
> so when edit action is executed I'm able to ask:
>
> this.list.getRowData() - and I get the an object, and can ask in this
> object for some distinct value, like id.
>
> and also if I want to link 2 different managed bean (like person -
> address relation)
>
> I use <tm:updateActionListener property="#{entity}" value="#{entity2.entity}"/>
>
> and
> <bean>entity2</bean>
> <managed-property>
>                        <property-name>entity</property-name>
>                        <value>#{ManagedBean for entity}</value>
>                </managed-property>
>
> Its all desribed in MyFaces WiKi, but maybe also will help someone.
>
>
>
> 2008/8/20 Anton Gavazuk <an...@gmail.com>:
>> Hi Volker,
>>
>> I'm already using this approach (by the way, its deprecated in 1.2)
>> I'm just interested if someone faces with the same situation and how
>> to solve it.
>>
>> 2008/8/20 Volker Weber <v....@inexso.de>:
>>> Hi Anton,
>>>
>>> 2008/8/20 Anton Gavazuk <an...@gmail.com>:
>>>> Hi Guy,
>>>>
>>>> thanks for answer
>>>>
>>>>>>All necessary beans will be instantiated automatically by JSF as long as you
>>>>>>define them in your faces-config.xml file.
>>>> its clear,
>>>> but I want to put some business related info in bean before showing them.
>>>> like following
>>>> JSF method {
>>>
>>> if you do here:
>>>  SomeBean  = facesContext.getApplication().getVariableResolver().resolveVariable(facesContext,
>>> "someBean");
>>> instead of
>>>> SomeBean = new SomeBean();
>>>
>>> it should work if you have "someBean" configured in faces-config.xml
>>>
>>>>  SomeBean.value1 =     Service.getSomething();
>>>>  SomeBean.value2 =     Service.getSomething();
>>>>
>>>>  SomeBean2 = new SomeBean2();
>>>> .....
>>>>  //now I can add these beans to faces context of course, but maybe
>>>> there is another way?
>>>> }
>>>>
>>>> I dont want to call business functions inside getters of managed beans.
>>>>
>>>>
>>>> 2008/8/20 Guy Bashan <gu...@gmail.com>:
>>>>> Hi,
>>>>>
>>>>> You can simply call all the beans directly from your JSP file.
>>>>> For example:
>>>>>
>>>>> <h:dataTable value="myFirstBean.someData" .../>
>>>>> <h:dataTable value="mySecondBean.someOtherData" .../>
>>>>>
>>>>> And so on...
>>>>>
>>>>> All necessary beans will be instantiated automatically by JSF as long as you
>>>>> define them in your faces-config.xml file.
>>>>>
>>>>> Guy.
>>>>>
>>>>> -----Original Message-----
>>>>> From: Anton Gavazuk [mailto:antongavazuk@gmail.com]
>>>>> Sent: Wednesday, August 20, 2008 11:33 AM
>>>>> To: MyFaces Discussion
>>>>> Subject: Composite view from several "request" managed beans
>>>>>
>>>>> Hi all,
>>>>>
>>>>> have maybe a silly question
>>>>>
>>>>> if I need to show a page which consists from several parts (modules)
>>>>> with different info, and this info cannot be stored in session beans,
>>>>> it should be refreshed on every request, so there is need for several
>>>>> managed beans with request scope.
>>>>>
>>>>> So if request forwards on such "composite"  page, should I create and
>>>>> put this beans in context manually in an JSF method or there is
>>>>> another way how to achieve this?
>>>>>
>>>>> Many thanks,
>>>>> Anton
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> inexso - information exchange solutions GmbH
>>> Bismarckstraße 13 | 26122 Oldenburg
>>> Tel.: +49 441 4082 356 |
>>> FAX: +49 441 4082 355 | www.inexso.de
>>>
>>
>

Re: Composite view from several "request" managed beans

Posted by Anton Gavazuk <an...@gmail.com>.
Ok, somehow out of scope but

very popular topic :) - send an parameter (for example in CRUD - send
an ID from list to view/edit screen)

my approach:

ManagedBean has getter for list and particular class field for list

so when edit action is executed I'm able to ask:

this.list.getRowData() - and I get the an object, and can ask in this
object for some distinct value, like id.

and also if I want to link 2 different managed bean (like person -
address relation)

I use <tm:updateActionListener property="#{entity}" value="#{entity2.entity}"/>

and
<bean>entity2</bean>
<managed-property>
			<property-name>entity</property-name>
			<value>#{ManagedBean for entity}</value>
		</managed-property>

Its all desribed in MyFaces WiKi, but maybe also will help someone.



2008/8/20 Anton Gavazuk <an...@gmail.com>:
> Hi Volker,
>
> I'm already using this approach (by the way, its deprecated in 1.2)
> I'm just interested if someone faces with the same situation and how
> to solve it.
>
> 2008/8/20 Volker Weber <v....@inexso.de>:
>> Hi Anton,
>>
>> 2008/8/20 Anton Gavazuk <an...@gmail.com>:
>>> Hi Guy,
>>>
>>> thanks for answer
>>>
>>>>>All necessary beans will be instantiated automatically by JSF as long as you
>>>>>define them in your faces-config.xml file.
>>> its clear,
>>> but I want to put some business related info in bean before showing them.
>>> like following
>>> JSF method {
>>
>> if you do here:
>>  SomeBean  = facesContext.getApplication().getVariableResolver().resolveVariable(facesContext,
>> "someBean");
>> instead of
>>> SomeBean = new SomeBean();
>>
>> it should work if you have "someBean" configured in faces-config.xml
>>
>>>  SomeBean.value1 =     Service.getSomething();
>>>  SomeBean.value2 =     Service.getSomething();
>>>
>>>  SomeBean2 = new SomeBean2();
>>> .....
>>>  //now I can add these beans to faces context of course, but maybe
>>> there is another way?
>>> }
>>>
>>> I dont want to call business functions inside getters of managed beans.
>>>
>>>
>>> 2008/8/20 Guy Bashan <gu...@gmail.com>:
>>>> Hi,
>>>>
>>>> You can simply call all the beans directly from your JSP file.
>>>> For example:
>>>>
>>>> <h:dataTable value="myFirstBean.someData" .../>
>>>> <h:dataTable value="mySecondBean.someOtherData" .../>
>>>>
>>>> And so on...
>>>>
>>>> All necessary beans will be instantiated automatically by JSF as long as you
>>>> define them in your faces-config.xml file.
>>>>
>>>> Guy.
>>>>
>>>> -----Original Message-----
>>>> From: Anton Gavazuk [mailto:antongavazuk@gmail.com]
>>>> Sent: Wednesday, August 20, 2008 11:33 AM
>>>> To: MyFaces Discussion
>>>> Subject: Composite view from several "request" managed beans
>>>>
>>>> Hi all,
>>>>
>>>> have maybe a silly question
>>>>
>>>> if I need to show a page which consists from several parts (modules)
>>>> with different info, and this info cannot be stored in session beans,
>>>> it should be refreshed on every request, so there is need for several
>>>> managed beans with request scope.
>>>>
>>>> So if request forwards on such "composite"  page, should I create and
>>>> put this beans in context manually in an JSF method or there is
>>>> another way how to achieve this?
>>>>
>>>> Many thanks,
>>>> Anton
>>>>
>>>>
>>>
>>
>>
>>
>> --
>> inexso - information exchange solutions GmbH
>> Bismarckstraße 13 | 26122 Oldenburg
>> Tel.: +49 441 4082 356 |
>> FAX: +49 441 4082 355 | www.inexso.de
>>
>

Re: Composite view from several "request" managed beans

Posted by Anton Gavazuk <an...@gmail.com>.
Hi Volker,

I'm already using this approach (by the way, its deprecated in 1.2)
I'm just interested if someone faces with the same situation and how
to solve it.

2008/8/20 Volker Weber <v....@inexso.de>:
> Hi Anton,
>
> 2008/8/20 Anton Gavazuk <an...@gmail.com>:
>> Hi Guy,
>>
>> thanks for answer
>>
>>>>All necessary beans will be instantiated automatically by JSF as long as you
>>>>define them in your faces-config.xml file.
>> its clear,
>> but I want to put some business related info in bean before showing them.
>> like following
>> JSF method {
>
> if you do here:
>  SomeBean  = facesContext.getApplication().getVariableResolver().resolveVariable(facesContext,
> "someBean");
> instead of
>> SomeBean = new SomeBean();
>
> it should work if you have "someBean" configured in faces-config.xml
>
>>  SomeBean.value1 =     Service.getSomething();
>>  SomeBean.value2 =     Service.getSomething();
>>
>>  SomeBean2 = new SomeBean2();
>> .....
>>  //now I can add these beans to faces context of course, but maybe
>> there is another way?
>> }
>>
>> I dont want to call business functions inside getters of managed beans.
>>
>>
>> 2008/8/20 Guy Bashan <gu...@gmail.com>:
>>> Hi,
>>>
>>> You can simply call all the beans directly from your JSP file.
>>> For example:
>>>
>>> <h:dataTable value="myFirstBean.someData" .../>
>>> <h:dataTable value="mySecondBean.someOtherData" .../>
>>>
>>> And so on...
>>>
>>> All necessary beans will be instantiated automatically by JSF as long as you
>>> define them in your faces-config.xml file.
>>>
>>> Guy.
>>>
>>> -----Original Message-----
>>> From: Anton Gavazuk [mailto:antongavazuk@gmail.com]
>>> Sent: Wednesday, August 20, 2008 11:33 AM
>>> To: MyFaces Discussion
>>> Subject: Composite view from several "request" managed beans
>>>
>>> Hi all,
>>>
>>> have maybe a silly question
>>>
>>> if I need to show a page which consists from several parts (modules)
>>> with different info, and this info cannot be stored in session beans,
>>> it should be refreshed on every request, so there is need for several
>>> managed beans with request scope.
>>>
>>> So if request forwards on such "composite"  page, should I create and
>>> put this beans in context manually in an JSF method or there is
>>> another way how to achieve this?
>>>
>>> Many thanks,
>>> Anton
>>>
>>>
>>
>
>
>
> --
> inexso - information exchange solutions GmbH
> Bismarckstraße 13 | 26122 Oldenburg
> Tel.: +49 441 4082 356 |
> FAX: +49 441 4082 355 | www.inexso.de
>

Re: Composite view from several "request" managed beans

Posted by Volker Weber <v....@inexso.de>.
Hi Anton,

2008/8/20 Anton Gavazuk <an...@gmail.com>:
> Hi Guy,
>
> thanks for answer
>
>>>All necessary beans will be instantiated automatically by JSF as long as you
>>>define them in your faces-config.xml file.
> its clear,
> but I want to put some business related info in bean before showing them.
> like following
> JSF method {

if you do here:
  SomeBean  = facesContext.getApplication().getVariableResolver().resolveVariable(facesContext,
"someBean");
instead of
> SomeBean = new SomeBean();

it should work if you have "someBean" configured in faces-config.xml

>  SomeBean.value1 =     Service.getSomething();
>  SomeBean.value2 =     Service.getSomething();
>
>  SomeBean2 = new SomeBean2();
> .....
>  //now I can add these beans to faces context of course, but maybe
> there is another way?
> }
>
> I dont want to call business functions inside getters of managed beans.
>
>
> 2008/8/20 Guy Bashan <gu...@gmail.com>:
>> Hi,
>>
>> You can simply call all the beans directly from your JSP file.
>> For example:
>>
>> <h:dataTable value="myFirstBean.someData" .../>
>> <h:dataTable value="mySecondBean.someOtherData" .../>
>>
>> And so on...
>>
>> All necessary beans will be instantiated automatically by JSF as long as you
>> define them in your faces-config.xml file.
>>
>> Guy.
>>
>> -----Original Message-----
>> From: Anton Gavazuk [mailto:antongavazuk@gmail.com]
>> Sent: Wednesday, August 20, 2008 11:33 AM
>> To: MyFaces Discussion
>> Subject: Composite view from several "request" managed beans
>>
>> Hi all,
>>
>> have maybe a silly question
>>
>> if I need to show a page which consists from several parts (modules)
>> with different info, and this info cannot be stored in session beans,
>> it should be refreshed on every request, so there is need for several
>> managed beans with request scope.
>>
>> So if request forwards on such "composite"  page, should I create and
>> put this beans in context manually in an JSF method or there is
>> another way how to achieve this?
>>
>> Many thanks,
>> Anton
>>
>>
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13 | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX: +49 441 4082 355 | www.inexso.de

RE: Composite view from several "request" managed beans

Posted by Guy Bashan <gu...@gmail.com>.
Hi,
I have never used the faces-config.xml injection. I used to initialize
anything in my bean constructors,
until I understood this is a bad thing to do... (at least for fetching data
from all sort of services...).
So currently this is what I am doing to initialize data:

private someData;

public List getSomeData()
{
  If (someData == null)
  {
    someData = myService.getData();
  }
  return someData;
}

In addition, if you want to pass a parameter to this page (it usually one
parameter, something like object id).
I simply use the regular query string mechanism for that. So all you have to
do is get the parameter from the request and initialize data using that
parameter (note that passing parameters in this method has not much of
support by core JSF).

If you want to further investigate, I am currently using in one of my
projects Seam framework, which is a great thing.
It has built-in facilities for initializing data and using request
parameters.


-----Original Message-----
From: Simon Kitching [mailto:skitching@apache.org] 
Sent: Wednesday, August 20, 2008 2:47 PM
To: MyFaces Discussion
Subject: Re: Composite view from several "request" managed beans

Anton Gavazuk schrieb:
>   
>>> All necessary beans will be instantiated automatically by JSF as long as
you
>>> define them in your faces-config.xml file.
>>>       
> its clear,
> but I want to put some business related info in bean before showing them.
> like following
> JSF method {
>   SomeBean = new SomeBean();
>   SomeBean.value1 =     Service.getSomething();
>   SomeBean.value2 =     Service.getSomething();
>
>   SomeBean2 = new SomeBean2();
> .....
>  //now I can add these beans to faces context of course, but maybe
> there is another way?
> }
>
> I dont want to call business functions inside getters of managed beans.
>   

If any class should be initialised before use, then the normal place to 
do that is in the class constructor.

If you need to have some values injected into your bean first, then 
unfortunately the constructor cannot be used as faces-config.xml does 
not support injecting of constructor-args. In that case, you can:
* use a better dependency-injection framework like Spring (spring can be 
used with JSF)
* use the @PostConstruct annotation to mark some method that should be 
called after injection is complete
  (but unfortunately there is a bug in myFaces that means this doesn't 
currently work)
* rely on the fact that injection always occurs in the order listed in 
the faces-config.xml file.

Regards,
Simon


Re: Composite view from several "request" managed beans

Posted by Simon Kitching <sk...@apache.org>.
Anton Gavazuk schrieb:
>   
>>> All necessary beans will be instantiated automatically by JSF as long as you
>>> define them in your faces-config.xml file.
>>>       
> its clear,
> but I want to put some business related info in bean before showing them.
> like following
> JSF method {
>   SomeBean = new SomeBean();
>   SomeBean.value1 =     Service.getSomething();
>   SomeBean.value2 =     Service.getSomething();
>
>   SomeBean2 = new SomeBean2();
> .....
>  //now I can add these beans to faces context of course, but maybe
> there is another way?
> }
>
> I dont want to call business functions inside getters of managed beans.
>   

If any class should be initialised before use, then the normal place to 
do that is in the class constructor.

If you need to have some values injected into your bean first, then 
unfortunately the constructor cannot be used as faces-config.xml does 
not support injecting of constructor-args. In that case, you can:
* use a better dependency-injection framework like Spring (spring can be 
used with JSF)
* use the @PostConstruct annotation to mark some method that should be 
called after injection is complete
  (but unfortunately there is a bug in myFaces that means this doesn't 
currently work)
* rely on the fact that injection always occurs in the order listed in 
the faces-config.xml file.

Regards,
Simon


Re: Composite view from several "request" managed beans

Posted by Anton Gavazuk <an...@gmail.com>.
Hi Guy,

thanks for answer

>>All necessary beans will be instantiated automatically by JSF as long as you
>>define them in your faces-config.xml file.
its clear,
but I want to put some business related info in bean before showing them.
like following
JSF method {
  SomeBean = new SomeBean();
  SomeBean.value1 =     Service.getSomething();
  SomeBean.value2 =     Service.getSomething();

  SomeBean2 = new SomeBean2();
.....
 //now I can add these beans to faces context of course, but maybe
there is another way?
}

I dont want to call business functions inside getters of managed beans.


2008/8/20 Guy Bashan <gu...@gmail.com>:
> Hi,
>
> You can simply call all the beans directly from your JSP file.
> For example:
>
> <h:dataTable value="myFirstBean.someData" .../>
> <h:dataTable value="mySecondBean.someOtherData" .../>
>
> And so on...
>
> All necessary beans will be instantiated automatically by JSF as long as you
> define them in your faces-config.xml file.
>
> Guy.
>
> -----Original Message-----
> From: Anton Gavazuk [mailto:antongavazuk@gmail.com]
> Sent: Wednesday, August 20, 2008 11:33 AM
> To: MyFaces Discussion
> Subject: Composite view from several "request" managed beans
>
> Hi all,
>
> have maybe a silly question
>
> if I need to show a page which consists from several parts (modules)
> with different info, and this info cannot be stored in session beans,
> it should be refreshed on every request, so there is need for several
> managed beans with request scope.
>
> So if request forwards on such "composite"  page, should I create and
> put this beans in context manually in an JSF method or there is
> another way how to achieve this?
>
> Many thanks,
> Anton
>
>

RE: Composite view from several "request" managed beans

Posted by Guy Bashan <gu...@gmail.com>.
Hi,

You can simply call all the beans directly from your JSP file.
For example:

<h:dataTable value="myFirstBean.someData" .../>
<h:dataTable value="mySecondBean.someOtherData" .../>

And so on...

All necessary beans will be instantiated automatically by JSF as long as you
define them in your faces-config.xml file.

Guy.

-----Original Message-----
From: Anton Gavazuk [mailto:antongavazuk@gmail.com] 
Sent: Wednesday, August 20, 2008 11:33 AM
To: MyFaces Discussion
Subject: Composite view from several "request" managed beans

Hi all,

have maybe a silly question

if I need to show a page which consists from several parts (modules)
with different info, and this info cannot be stored in session beans,
it should be refreshed on every request, so there is need for several
managed beans with request scope.

So if request forwards on such "composite"  page, should I create and
put this beans in context manually in an JSF method or there is
another way how to achieve this?

Many thanks,
Anton