tags:

views:

23

answers:

2

Can we have something like following in case of HTML + JSF

<meta  name="description" content="#{MyBean.attr}"/>

i.e. can we set the value of "description" meta attribute dynmically?

+3  A: 

This will work when you're using JSF with Facelets as view technology. However, since you're asking this question it seems that you're using legacy JSP as view technology wherein unified EL (those #{} things) in template text isn't supported. You need to use JSF h:outputText component then to print the bean property.

<meta name="description" content="<h:outputText value="#{MyBean.attr}" />" />

Ugly, yes, but that's the payoff of sticking to a legacy view technology which isn't originally designed with JSF in mind ;) If you're curious about Facelets, have a look at its docbook. It's by the way the default view technology in JSF 2.0 and newer.

BalusC
1+ ..................
org.life.java
Thanks BalusC, this fixed my issue.......
Abhishek
A: 

In pure HTML, no, it's not possible. If you configured your servlet mapping in web.xml to something of this effect (example):

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

Then, by all means. Also, you must have a library that can interpret OGNL.
Update Alternatively, see BalusC's answer.

The Elite Gentleman
OGNL should not be confused with [unified/deferred EL](http://download.oracle.com/javaee/6/tutorial/doc/gjddd.html). OGNL is used in Struts2 only. This question is tagged `jsf`.
BalusC
Thanks BalusC, didn't see that.
The Elite Gentleman
In your comment on the deleted answer of someone else who had ASP in mind you however explicitly stated JSF.
BalusC
I might have quoted JSF, but I thought JSP 2.0 with Struts2. I was actually responding to a comment from this question: http://stackoverflow.com/questions/3962478/struts2-anchor-tag-doesnt-include-contextpath/3962503#3962503
The Elite Gentleman