tags:

views:

1003

answers:

3

Hi,

I want to create links using database columns. I have a backing bean where I 'm connecting to the database. There is no problem with the connection and also no problem with the links names. I can see my links on my browser. I want to use onclick function and that's exactly where the problem starts. How can I use or can I use EL in onclick?

A little example:

<h:dataTable rows="7" value="#{frontSiteMenu.links}" var="row"
 styleClass="sitemenu" width="200">
 <h:column>
  <a href="#" onclick="dispNewsGroup('${row.newsGroupId}')"><h:outputText value='#{row.newsGroup}' /></a>
 </h:column>
</h:dataTable>

Thanks.

+3  A: 

I take it you are using JSPs?

Use h:outputLink instead of an a tag and change the expression use the # character:

<h:outputLink value="#" onclick="dispNewsGroup('#{row.newsGroupId}')">
    <h:outputText value='#{row.newsGroup}' />
</h:outputLink>

That is untested, but should be close to what you want.

The spec says this about # vs $:

...by convention the J2EE web tier specifications use the ${expr} construct for immediate evaluation and the #{expr} construct for deferred evaluation.

So, in a repeat control where the underlying values change, it is desirable to use deferred evaluation.

There are also issues with using non-JSF tags as children of some JSF controls, so it is best to stick to using JSF controls where possible (though there is a f:verbatim tag). Many of these issues go away if you move to the newer Facelets view technology.

McDowell
A: 

Thank you so much.

But I'm using MyEclipse and I'm new at JSF. Do you know something like Facelets in MyEclipse?

I _think_ Exadel Studio has Facelets tooling support, but I've never used it. Jim Driscoll wrote a post on the state of JSF 2 (which includes Facelets) support: http://weblogs.java.net/blog/driscoll/archive/2009/05/using_an_ide_to_1.html I do not _think_ there is any support in MyEclipse at the moment, but then I have never used it. You can do Facelets development in Eclipse, but may not get WYSIWG support. You can overcome JSF/JSP issues - it just isn't as easy as it is with Facelets.
McDowell
A: 

Thank you so much for your help.