You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Bill Dudney <bd...@mac.com> on 2005/04/21 04:33:48 UTC

Re: Action problem with Tiles

Hi,

I have an application that works. Here is the simplified JSP code (from 
foo.jsp);

				<h:commandLink action="#{mybean.action}">
                      <h:outputText value="#{mybean.displayValue}"/>
				</h:commandLink>

And here is the definition of 'mybean' in the config file

   <managed-bean>
   	<description>
   		blah blah
   	</description>
   	<managed-bean-name>mybean</managed-bean-name>
   	<managed-bean-class>com.example.MyBean</managed-bean-class>
   	<managed-bean-scope>request</managed-bean-scope>
   </managed-bean>

And the action method;

   public String displayValue() {
     return "outcome";
   }

And finally the navigation stuff;

   <navigation-rule>
   	<from-view-id>/foo.jsp</from-view-id>
   	<navigation-case>
   		<from-outcome>outcome</from-outcome>
   		<to-view-id>/bar.jsp</to-view-id>
   	</navigation-case>
   </navigation-rule>

bar.jsp displays some details of the 'displayValue' (from the 
simplified JSP code above).

What you have to keep in mind is the bean behind 'bar.jsp' will be new 
if its created in request scope. So if displayValue has to look up some 
info and then stuff it into the bar's backing bean it must have a 
handle on the instance that is created for the current request. You can 
do that in your config with a bean reference. Here is the bean element 
for the barBean;

   <managed-bean>
     <description>
       bar bar
     </description>
     <managed-bean-name>barBean</managed-bean-name>
     <managed-bean-class>com.example.BarBean</managed-bean-class>
     <managed-bean-scope>request</managed-bean-scope>
   </managed-bean>

The managed-bean element for 'mybean' would then need to be updated to 
look like this;

   <managed-bean>
   	<description>
   		blah blah
   	</description>
   	<managed-bean-name>mybean</managed-bean-name>
   	<managed-bean-class>com.example.MyBean</managed-bean-class>
   	<managed-bean-scope>request</managed-bean-scope>
     <managed-property>
       <property-name>gumpy</property-name>
       <value>#{barBean}</value>
     </managed-property>
   </managed-bean>

Now com.example.MyBean needs to have a get/set method pair for gumpy 
(i.e. getGumpy and setGumpy). Then you modify the displayValue method 
to look like this;

   public String displayValue() {
     gumpy.setValueOne(...);
     return "outcome";
   }

Then in your bar.jsp you can refer to barBean.valueOne and it will have 
the value supplied by the invocation of mybean.displayValue().

The property is called gumpy in an attempt to not be confusing with 
naming the property after the managed bean (i.e. the value of 
managed-bean-name). In many cases you might want to name them the same 
(i.e. the property would be barBean instead of gumpy). If gumpy is more 
confusing, I'm sorry and please replace gumpy with barBean.

I hope this helps.

TTFN,

-bd-

On Apr 20, 2005, at 10:24 AM, AUGE Frédéric GC EUR wrote:

> Hi,
>
> I'm starting a new webapp with MyFaces 1.0.9 (this isn't my first one 
> with
> MyFaces) and decided to use Tiles.
> My problem is with commandLink that won't fire any action when inside a
> dataTable. The action method isn't called.
> Is it a known problem ? anyone to say that it works ?
>
> This simplified JSP code demonstrate the problem:
>
> <x:dataTable id="ticketsList"
> 	width="100%"
>     var="currentBean"
>     value="#{tckListBean.tickets}"
> 	preserveDataModel="false">
> 	<h:column>
> 		<f:facet name="header">
> 			<h:outputText value="#{appBundle.tckListTicket}" />
> 		</f:facet>
> 		<h:commandLink action="#{tckTicketBean.showTicketAction}">
> 			<h:outputText value="ssss"/>
> 		</h:commandLink>
> 	</h:column>
> </x:dataTable>
>
> If I put the same commandLink just before the dataTable, it works 
> perfectly
> !
>
> Thanks for any input,
> Frederic
>

RE: Action problem with Tiles

Posted by AUGE Frédéric GC EUR <fr...@globecast.com>.
Hi,

Thanks very much for answers.

In fact, it has nothing to do with tiles, but with the scopes of the beans.
In this new application I'll try to keep as less informations as possible in
the session, and that was the problem. Changing to session the managed bean
behind the page with the dataTable makes my commandLink works :-)
Then I tried back to request and set the attribute preserveDataModel="true"
of the dataTable and it works, great MyFaces !

Frederic

-----Message d'origine-----
De : Bill Dudney [mailto:bdudney@mac.com]
Envoyé : jeudi 21 avril 2005 04:34
À : MyFaces Discussion
Objet : Re: Action problem with Tiles


  Hi,

  I have an application that works. Here is the simplified JSP code (from
foo.jsp);

  <h:commandLink action="#{mybean.action}">
  <h:outputText value="#{mybean.displayValue}"/>
  </h:commandLink>

  And here is the definition of 'mybean' in the config file

  <managed-bean>
  <description>
  blah blah
  </description>
  <managed-bean-name>mybean</managed-bean-name>
  <managed-bean-class>com.example.MyBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>

  And the action method;

  public String displayValue() {
  return "outcome";
  }

  And finally the navigation stuff;

  <navigation-rule>
  <from-view-id>/foo.jsp</from-view-id>
  <navigation-case>
  <from-outcome>outcome</from-outcome>
  <to-view-id>/bar.jsp</to-view-id>
  </navigation-case>
  </navigation-rule>

  bar.jsp displays some details of the 'displayValue' (from the simplified
JSP code above).

  What you have to keep in mind is the bean behind 'bar.jsp' will be new if
its created in request scope. So if displayValue has to look up some info
and then stuff it into the bar's backing bean it must have a handle on the
instance that is created for the current request. You can do that in your
config with a bean reference. Here is the bean element for the barBean;

  <managed-bean>
  <description>
  bar bar
  </description>
  <managed-bean-name>barBean</managed-bean-name>
  <managed-bean-class>com.example.BarBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>

  The managed-bean element for 'mybean' would then need to be updated to
look like this;

  <managed-bean>
  <description>
  blah blah
  </description>
  <managed-bean-name>mybean</managed-bean-name>
  <managed-bean-class>com.example.MyBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
  <property-name>gumpy</property-name>
  <value>#{barBean}</value>
  </managed-property>
  </managed-bean>

  Now com.example.MyBean needs to have a get/set method pair for gumpy (i.e.
getGumpy and setGumpy). Then you modify the displayValue method to look like
this;

  public String displayValue() {
  gumpy.setValueOne(...);
  return "outcome";
  }

  Then in your bar.jsp you can refer to barBean.valueOne and it will have
the value supplied by the invocation of mybean.displayValue().

  The property is called gumpy in an attempt to not be confusing with naming
the property after the managed bean (i.e. the value of managed-bean-name).
In many cases you might want to name them the same (i.e. the property would
be barBean instead of gumpy). If gumpy is more confusing, I'm sorry and
please replace gumpy with barBean.

  I hope this helps.

  TTFN,

  -bd-

  On Apr 20, 2005, at 10:24 AM, AUGE Frédéric GC EUR wrote:


    Hi,

    I'm starting a new webapp with MyFaces 1.0.9 (this isn't my first one
with
    MyFaces) and decided to use Tiles.
    My problem is with commandLink that won't fire any action when inside a
    dataTable. The action method isn't called.
    Is it a known problem ? anyone to say that it works ?

    This simplified JSP code demonstrate the problem:

    <x:dataTable id="ticketsList"
    width="100%"
    var="currentBean"
    value="#{tckListBean.tickets}"
    preserveDataModel="false">
    <h:column>
    <f:facet name="header">
    <h:outputText value="#{appBundle.tckListTicket}" />
    </f:facet>
    <h:commandLink action="#{tckTicketBean.showTicketAction}">
    <h:outputText value="ssss"/>
    </h:commandLink>
    </h:column>
    </x:dataTable>

    If I put the same commandLink just before the dataTable, it works
perfectly
    !

    Thanks for any input,
    Frederic