java code in inputText
i am trying to include a java code into the value of the inputText in my jsf page but an error occur
according to tld or attribute directive in tag file attribute value does not accept any expressions
Here is my jsf page.
<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %>
<%@ page language="java" %>
<core:view>
<html:form>
<html:outputLabel value="Informations " style="FONT-SIZE: xx-large;"/>
<br />
<br />
<%
final String property=System.getProperty("jboss.server.home.dir");
%>
<html:outputLabel value="Répertoire de configuration: " />
<html:inputText value='<%=property%>'/>
</html:form>
</core:view>
Doesn ' t work either wi开发者_如何转开发th double quote or nothing How to resolve this problem please ? Thank you very much
The problem is with this line of code:
<html:inputText value='<%=property%>'/>
JSF uses Expression Language to populate/read values to/from a JavaBean. You will have to create a POJO action (called ManagedBean) with a variable property
and link it there.
E.g.
public class ConfigurationAction {
private String property = System.getProperty("jboss.server.home.dir");
/**NOTE: MUST create a getter and setter. **/
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
}
Don't forget to map the ManagedBean. In JBoss Seam, you will just add an @Name
annotation above the class like, @Name("configurationAction")
.
Finally, render this in JSF with Expression Language (EL)
<html:inputText value="#{configurationAction.property}"/>
Where configurationAction
is the name of your ManagedBean, and property
is the instance of the ManagedBean.
精彩评论