]
Stan Silvert commented on JBSEAM-329:
-------------------------------------
A couple of other points that might be good for the docs:
1) This is an alternative to @In. Say you have a Seam component with many action
methods. Injection will happen for @In with every method called - even if the variable is
only used in a single method. So, passing it as a param might make more sense than using
@In.
2) This will work any managed bean rather than just for Seam components. So, I can
declare a managed bean in faces-config.xml and still use action params.
Allow parameters to be passed into actions
------------------------------------------
Key: JBSEAM-329
URL:
http://jira.jboss.com/jira/browse/JBSEAM-329
Project: JBoss Seam
Issue Type: Feature Request
Affects Versions: 1.1
Reporter: Stan Silvert
Assigned To: Stan Silvert
Fix For: 1.1
USAGE
The Action Params feature allows you to specify parameters when using the EL to call an
action. So I can have something like this:
<s:commandButton action="#{hotelBooking.bookHotel(hotel, user)}"
class="button" value="Book Hotel" />
The parameters hotel and user will be evaluated as ValueExpressions and passed into the
bookHotel method of your managed bean. This gives you an alternative to @In which forces
injection to happen on every action method called.
You can also pass in literal Strings using single or double quotes:
<s:commandLink action="#{foo.bar( 'Here is my message' )}"
value="Click Here" />
<s:commandLink action='#{foo.bar( "Here is my message" )}'
value='Click Here' />
You might want to use this notation for all of your action methods, even when you
don't have params to pass. This improves readability by making it clear that the
expression is a MethodExpression and not a ValueExpression:
<s:link value="Cancel" action="#{ hotelBooking.cancel() }"
buttonClass="button" linkStyle="button"/>
This is very handy for passing in JSF implicit objects:
<page view-id="/mypage.jsp" action="#{foo.myMethod(facesContext,
view)}" />
If you desire, you can still use the [ ] operator for your method as defined in the EL
spec. If you do, you should put both the method and the params inside the [ ]:
<s:commandLink action="#{ foo[ bar( facesContext ) ] }" value="Click
Here" />
NEW TAGS
As seen in the examples, Seam now has two new tags:
<s:commandButton>
<s:commandLink>
These are drop-in replacements for <h:commandButton> and <h:commandLink>.
For Facelets, the "class" attribute is added just as it is in the Facelets
implementation of the corresponding tag.
Note that these are JSF 1.1 style tags so they will not always work properly with
<c:forEach>. Fixing this requires that the tags be written in the JSF 1.2 style.
So, this can be fixed if and when we can assume JSF 1.2 is present.
OLD TAGS
<s:link> now supports action params.
Actions defined in pages.xml now support action params as well.
FACELETS SUPPORT
To enable action params in Facelets, you will need to use the new SeamFaceletViewHandler
instead of FaceletViewHandler. So, in faces-config.xml you will have:
<application>
<view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>
</application>
ISSUES
Normally, when a MethodExpression or MethodBinding is created, the parameter types are
passed in by hand. In the case of an action, JSF assumes that there are no params to
pass. With action params in an expression, you can't know the param types until the
parameters are evaluated. Evaluation of the params doesn't happen until the
MethodExpression is invoked. This has two minor consequences:
1) If you call invoke on the MethodExpression by hand, any params you pass may be
ignored. Params defined in the expression will take precedence.
2) Since Facelets uses MethodExpression instead of MethodBinding, you would
normally be able to call myMethodExpression.getMethodInfo().getParamTypes() at any time.
For an expression containing action params, you will only be able to do this after the
method has been invoked at least once.
Both of these cases are exceedingly rare and only apply when you want to invoke the
MethodExpression by hand.
Unlike other MethodExpressions and MethodBindings, with action params the method to
invoke must be determined from the expression itself. It determines the right method
based on these criteria:
1) The method name must match the method name in the expression
2) The number of parameters must match the number of params in the expression.
It is possible, though unlikely, that more than one method will match the criteria. In
that case, an exception is thrown explaining the criteria. I can probably fix this at
some point, but it gets a little hairy.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: