Aleksei,
On 7/19/05, Aleksei Valikov <[EMAIL PROTECTED]> wrote:
> Hi.
>
> > Instead, IMHO, the expression language should encourage you to
> > manipulate server side model data with model tier techniques ... it
> > was designed to serve as a *binding* between the tiers, rather than as
> > a general purpose computational technology. If we had wanted that, we
> > would likely have adopted essentially the entire JavaScript language
> > as the expression language mechanism in the first place (it was
> > considered and rejected during the initial deliberations in the JSTL
> > expert group, for the reasons outlined above).
>
> Well, probably I'm missing something.
> Here's a simple example. I have a documentDao with the possibility to
> load document and give back the document list. I want to display a
> table, where rows correspond to the documents returned by the dao. In
> every row, I'd like to have a "Load" button to load the corresponding
> document.
> With JS in EL it is as easy as #{[documentDao.load(document)]} as a
> button action.
>
> What would be the easiest way to implement this with standard EL,
> without JS?
Let's assume (for completeness) that the backing bean exposing the
table data model is different from the backing bean exposing the
per-row loadDocument logic.
Say the table data model is available via value binding
#{modelBean.tableData}, at session scope, and the application logic to
load the document is available via action method binding
#{logicBean.loadDocument}, at request scope. A per-row commandLink's
actionListener attribute is bound to #{logicBean.loadDocument}.
In faces-config.xml managed bean section, a managed property, say
"model", of the "logicBean" can be initialized with
#{modelBean.tableData}. This will cause a setModel method on
logicBean to be called when logicBean is instantiated, passing the
table data model as a parameter. This allows it to be stored inside
logicBean, even though logicBean has no prior knowledge of the table
data.
When the commandLink is clicked for a particular row in the table, the
current row is established in the table data model prior to action
event delivery.
So, inside logicBean's loadDocument(ActionEvent) method, during action
event delivery, the table data model can be observed, knowing that it
is pointing to the right row, and the desired data model column values
for that row can be used to correctly parameterize the behavior of
loadDocument.
Note that this strategy uses the currency in the data model to act as
a common storage area where implicit context can be passed to the
behavioral method binding. Therefore, it is not a general purpose
mechanism for parameter passing, because it does not cover cases where
the desired parameters are not represented in the data model.
However, it does seem to cover your usecase, which is a common one.
Kind Regards,
John Fallows.