|
Hi Jorge,
This question gets asked quite a lot. No you can't pass
arguments to methods invoked from JSTL expressions - annoying isn't it!
Usually you would have separate accessors for each thing you want to access - if
you need to use this 'getField('fieldname')' style you'll need to put some sort
of adapter class in between. There are a couple of ways to
implicitly pass parameters in to methods though - basically by setting
state within the page using the <t:saveState> component (http://wiki.apache.org/myfaces/How_JSF_State_Management_Works) or
within the scoped beans themselves - I prefer the latter to be honest as it's
more elegant
There are also a couple of crazy ways of invoking arbitrary
methods and parameters by setting up state by either of these methods and then
calling a method that looks up the details of what you want to invoke and uses
introspection/reflection to invoke it. e.g.
<x:saveState id="obj"
value="fld">
<x:saveState id="method"
value="getField">
<x:saveState id="param1"
value="DESCR">
and then have the parameterless method look up these
values, invoke the appropriate method with the appropriate parameters and return
the value. But to be honest, that's CRAZY. You'd have to have a
pretty good reason to try this sort of thing!
Hope that's of some help.
Jim
--
Jim Moores, Developer, SmartSpread Limited,
UK.
From: Jorge Vásquez
[mailto:[EMAIL PROTECTED]
Sent: 21 July 2006 23:29 To: 'MyFaces Discussion' Subject: ManagedBean methods with arguments... Hi, I was wondering if JSF supports
invoking methods in ManagedBeans that have input
arguments.. For instance, how can I convert the
following pure jsp code to jsf style (I am particularly interested in conversion
for the method: getField(String arg)):
<%
String dlen = "0";
for
(int
i = 0; i < flds.getCollCount(); i++){
altDataField fld = (altDataField)flds.getCollObject(i);
String fldVal =
(String)fldVals.get(fld.m_userColumn);
if
(Integer.parseInt(fld.m_entryLength) > 40) dlen = "40";
else
dlen = fld.m_entryLength; %>
<TR>
<TD
align=right><%=
fld.getField("DESCR")
%> </TD>
<TD><INPUT
id="<%= fld.getField("USERCOLUMN") %>" name="<%= fld.getField("USERCOLUMN") %>" size=<%= dlen %> maxlength=<%= fld.getField("ENTRYLENGTH") %> value="<%= fldVal %>"></input> </TD>
<TD><input
checked
type="checkbox"
name="chk<%= fld.getField("USERCOLUMN") %>" value="1"></input></TD>
<TD><input
type="radio"
name="orderby"
value="<%= fld.getField("USERCOLUMN") %>"></input></TD>
</TR>
<%
} %> Regards, Jorge
Vásquez |

