You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Helmut Swaczinna <sw...@wlp-systems.de> on 2008/01/08 11:20:13 UTC

How to use one subview more than once in one page

Hi,

I want to use a subview multiple times in one jsf page. The layout and 
function of the subviews are identical
but each subview should display different data. So every intance of the 
subview must use a different
instance of the backing bean (controller). I've searched and tested for a 
solution but found only a really
ugly one.

This is an example (with Tobago, but that's a general jsf issue):

main.jsp

<f:view>
  <tc:page id="testPage" width="300px" height="200px">
    <f:subview id="subView1">
      <jsp:include page="subview.jsp">
        <jsp:param name="beanName" value="controller1"/>
      </jsp:include>
    </f:subview>
    <f:subview id="subView2">
      <jsp:include page="subview.jsp">
        <jsp:param name="beanName" value="controller2"/>
      </jsp:include>
    </f:subview>
  </tc:page>
</f:view>

subview.jsp

<tc:panel>
  <% String beanName = request.getParameter("beanName"); %>
  <tc:panel>
    <f:facet name="layout">
      <tc:gridLayout rows="fixed" columns="1*;1*;1*"/>
    </f:facet>
    <tc:out id="out" value='<%= "#{" + beanName + ".value}" %>'/>
    <tc:in id="in" value='<%= "#{" + beanName + ".value2}" %>'/>
    <tc:button id="button" label="<%= beanName %>" action='<%= "#{" + 
beanName + ".subviewAction}" %>'/>
  </tc:panel>
</tc:panel>

I think, there must be a better solution for this problem. (I know with 
facelets there is a solution, but I
don't want to port my complex application to facelets.)

Regards
Helmut




Re: How to use one subview more than once in one page

Posted by Helmut Swaczinna <sw...@wlp-systems.de>.
Hi Mario,

thanks for the hint. This is what I was looking for. But unfortunately 
t:aliasBean does not work with
component bindings and I need them. There's a workaround mentoined in the 
t:aliasBean wiki but I
don't understand it right know. Hm, maybe I should use my own solution which 
works even with
component bindings...

Regards
Helmut

----- Original Message ----- 
From: "Mario Ivankovits" <ma...@ops.co.at>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
Sent: Tuesday, January 08, 2008 11:26 AM
Subject: Re: How to use one subview more than once in one page


> Hi!
>> <% String beanName = request.getParameter("beanName"); %>
>>  <tc:panel>
>>    <f:facet name="layout">
>>      <tc:gridLayout rows="fixed" columns="1*;1*;1*"/>
>>    </f:facet>
>>    <tc:out id="out" value='<%= "#{" + beanName + ".value}" %>'/>
>>    <tc:in id="in" value='<%= "#{" + beanName + ".value2}" %>'/>
> Woho .... would never have thought about such a solution myself :-)
> kudos to you.
>
> If you already use tomahawk have a look at the aliasBean which allows
> you to get rid of the JSP stuff.
>
>            <t:aliasBeansScope>
>                <t:aliasBean alias="#{quickSwitchToolbarData}"
> value="#{toolbar.toolbarData}">
>                    <jsp:include page="xyz.page" />
>                </t:aliasBean>
>            </t:aliasBeansScope>
>
> This allows you to use "quickSwitchToolbarData" from within your include.
>
> Ciao,
> Mario
>
> 


Re: How to use one subview more than once in one page

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

we use jsp tags instead of jsp:include. In tags you can define attributes e.g:

WEB-INF/tags/userList.tag:
---------------------------------------------------------------------------
<%@ attribute name="controller" %>
<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>

<tc:sheet value="#{${controller}.users}" var="user
    columns="20px;15px;20px;90px;90px;20px;30*;20*;70px;12*;12*;6*;12*;12*;1*"
    pagingLength="30"
    binding="#{${controller}.sheet}">
 ...
</tc:sheet>
---------------------------------------------------------------------------

and on the page to use it:
---------------------------------------------------------------------------
<%@ taglib tagdir="/WEB-INF/tags/" prefix="tags" %>

...

 <tags:userList controller="#{searchController}"/>

...
---------------------------------------------------------------------------


Regards,
    Volker

2008/1/8, Helmut Swaczinna <sw...@wlp-systems.de>:
> Hi Volker,
>
> this looks nice.
>
> How do you set the beanName in subview.jsp?
>
> I do this:
>
>   <%
>     String beanName = request.getParameter("beanName");
>     request.setAttribute("beanName", beanName);
>   %>
>
> This works fine when I navigate for the first time to the page. But when I
> navigate to another page and back
> ${beanName} is empty.
>
> Regards
> Helmut
>
>
> ----- Original Message -----
> From: "Volker Weber" <v....@inexso.de>
> To: "MyFaces Discussion" <us...@myfaces.apache.org>
> Sent: Tuesday, January 08, 2008 12:36 PM
> Subject: Re: How to use one subview more than once in one page
>
>
> > Hi,
> >
> > we are using a similar code in our project in the subview.jsp:
> >
> >   <tc:out id="out" value="#{${beanName}.value}"/>
> >   <tc:in id="in" value="#{${beanName}.value2}"/>
> >   <tc:button id="button" label="${beanName}"
> > action=#{${beanName}.subviewAction}"/>
> >
> > The tomahawk aliasBean stuff did not work in tobago if you use
> > partiall reload or any component binding inside the subview.
> >
> > The tomahawk aliasBean stuff also can't work with the sun RI when using
> > binding.
> >
> > Maybe we can add something like the aliasBean into tobago, i thought
> > about adding a aliasPanel like:
> >
> > <tc:aliasPanel >
> >  <tc:alias alias="name" value="#{bean}"/>
> >  ...
> > <tc:aliasPanel >
> >
> > where the aliasPanel is an extended tc:panel.
> >
> > But i'm too busy with other problems now.
> >
> >
> > Regards,
> >    Volker
> >
> > 2008/1/8, Mario Ivankovits <ma...@ops.co.at>:
> >> Hi!
> >> > <% String beanName = request.getParameter("beanName"); %>
> >> >  <tc:panel>
> >> >    <f:facet name="layout">
> >> >      <tc:gridLayout rows="fixed" columns="1*;1*;1*"/>
> >> >    </f:facet>
> >> >    <tc:out id="out" value='<%= "#{" + beanName + ".value}" %>'/>
> >> >    <tc:in id="in" value='<%= "#{" + beanName + ".value2}" %>'/>
> >> Woho .... would never have thought about such a solution myself :-)
> >> kudos to you.
> >>
> >> If you already use tomahawk have a look at the aliasBean which allows
> >> you to get rid of the JSP stuff.
> >>
> >>             <t:aliasBeansScope>
> >>                 <t:aliasBean alias="#{quickSwitchToolbarData}"
> >> value="#{toolbar.toolbarData}">
> >>                     <jsp:include page="xyz.page" />
> >>                 </t:aliasBean>
> >>             </t:aliasBeansScope>
> >>
> >> This allows you to use "quickSwitchToolbarData" from within your include.
> >>
> >> Ciao,
> >> Mario
> >>
> >>
> >
> >
> > --
> > inexso - information exchange solutions GmbH
> > Bismarckstraße 13      | 26122 Oldenburg
> > Tel.: +49 441 4082 356 |
> > FAX:  +49 441 4082 355 | www.inexso.de
> >
>
>


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

Re: How to use one subview more than once in one page

Posted by Helmut Swaczinna <sw...@wlp-systems.de>.
Hi Volker,

this looks nice.

How do you set the beanName in subview.jsp?

I do this:

  <%
    String beanName = request.getParameter("beanName");
    request.setAttribute("beanName", beanName);
  %>

This works fine when I navigate for the first time to the page. But when I 
navigate to another page and back
${beanName} is empty.

Regards
Helmut


----- Original Message ----- 
From: "Volker Weber" <v....@inexso.de>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
Sent: Tuesday, January 08, 2008 12:36 PM
Subject: Re: How to use one subview more than once in one page


> Hi,
>
> we are using a similar code in our project in the subview.jsp:
>
>   <tc:out id="out" value="#{${beanName}.value}"/>
>   <tc:in id="in" value="#{${beanName}.value2}"/>
>   <tc:button id="button" label="${beanName}"
> action=#{${beanName}.subviewAction}"/>
>
> The tomahawk aliasBean stuff did not work in tobago if you use
> partiall reload or any component binding inside the subview.
>
> The tomahawk aliasBean stuff also can't work with the sun RI when using 
> binding.
>
> Maybe we can add something like the aliasBean into tobago, i thought
> about adding a aliasPanel like:
>
> <tc:aliasPanel >
>  <tc:alias alias="name" value="#{bean}"/>
>  ...
> <tc:aliasPanel >
>
> where the aliasPanel is an extended tc:panel.
>
> But i'm too busy with other problems now.
>
>
> Regards,
>    Volker
>
> 2008/1/8, Mario Ivankovits <ma...@ops.co.at>:
>> Hi!
>> > <% String beanName = request.getParameter("beanName"); %>
>> >  <tc:panel>
>> >    <f:facet name="layout">
>> >      <tc:gridLayout rows="fixed" columns="1*;1*;1*"/>
>> >    </f:facet>
>> >    <tc:out id="out" value='<%= "#{" + beanName + ".value}" %>'/>
>> >    <tc:in id="in" value='<%= "#{" + beanName + ".value2}" %>'/>
>> Woho .... would never have thought about such a solution myself :-)
>> kudos to you.
>>
>> If you already use tomahawk have a look at the aliasBean which allows
>> you to get rid of the JSP stuff.
>>
>>             <t:aliasBeansScope>
>>                 <t:aliasBean alias="#{quickSwitchToolbarData}"
>> value="#{toolbar.toolbarData}">
>>                     <jsp:include page="xyz.page" />
>>                 </t:aliasBean>
>>             </t:aliasBeansScope>
>>
>> This allows you to use "quickSwitchToolbarData" from within your include.
>>
>> Ciao,
>> Mario
>>
>>
>
>
> -- 
> inexso - information exchange solutions GmbH
> Bismarckstraße 13      | 26122 Oldenburg
> Tel.: +49 441 4082 356 |
> FAX:  +49 441 4082 355 | www.inexso.de
> 


Re: How to use one subview more than once in one page

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

we are using a similar code in our project in the subview.jsp:

   <tc:out id="out" value="#{${beanName}.value}"/>
   <tc:in id="in" value="#{${beanName}.value2}"/>
   <tc:button id="button" label="${beanName}"
action=#{${beanName}.subviewAction}"/>

The tomahawk aliasBean stuff did not work in tobago if you use
partiall reload or any component binding inside the subview.

The tomahawk aliasBean stuff also can't work with the sun RI when using binding.

Maybe we can add something like the aliasBean into tobago, i thought
about adding a aliasPanel like:

<tc:aliasPanel >
  <tc:alias alias="name" value="#{bean}"/>
  ...
<tc:aliasPanel >

where the aliasPanel is an extended tc:panel.

But i'm too busy with other problems now.


Regards,
    Volker

2008/1/8, Mario Ivankovits <ma...@ops.co.at>:
> Hi!
> > <% String beanName = request.getParameter("beanName"); %>
> >  <tc:panel>
> >    <f:facet name="layout">
> >      <tc:gridLayout rows="fixed" columns="1*;1*;1*"/>
> >    </f:facet>
> >    <tc:out id="out" value='<%= "#{" + beanName + ".value}" %>'/>
> >    <tc:in id="in" value='<%= "#{" + beanName + ".value2}" %>'/>
> Woho .... would never have thought about such a solution myself :-)
> kudos to you.
>
> If you already use tomahawk have a look at the aliasBean which allows
> you to get rid of the JSP stuff.
>
>             <t:aliasBeansScope>
>                 <t:aliasBean alias="#{quickSwitchToolbarData}"
> value="#{toolbar.toolbarData}">
>                     <jsp:include page="xyz.page" />
>                 </t:aliasBean>
>             </t:aliasBeansScope>
>
> This allows you to use "quickSwitchToolbarData" from within your include.
>
> Ciao,
> Mario
>
>


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

Re: How to use one subview more than once in one page

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> <% String beanName = request.getParameter("beanName"); %>
>  <tc:panel>
>    <f:facet name="layout">
>      <tc:gridLayout rows="fixed" columns="1*;1*;1*"/>
>    </f:facet>
>    <tc:out id="out" value='<%= "#{" + beanName + ".value}" %>'/>
>    <tc:in id="in" value='<%= "#{" + beanName + ".value2}" %>'/>
Woho .... would never have thought about such a solution myself :-)
kudos to you.

If you already use tomahawk have a look at the aliasBean which allows
you to get rid of the JSP stuff.

            <t:aliasBeansScope>
                <t:aliasBean alias="#{quickSwitchToolbarData}"
value="#{toolbar.toolbarData}">
                    <jsp:include page="xyz.page" />
                </t:aliasBean>
            </t:aliasBeansScope>

This allows you to use "quickSwitchToolbarData" from within your include.

Ciao,
Mario