gpt4 book ai didi

inputText中的java代码

转载 作者:行者123 更新时间:2023-12-01 19:14:42 24 4
gpt4 key购买 nike

我试图将 java 代码包含到我的 jsf 页面中的 inputText 值中,但发生错误

according to tld or attribute directive in tag file attribute value does not accept any expressions

这是我的 jsf 页面。

<%@ 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 />&nbsp;
<br />

<%
final String property=System.getProperty("jboss.server.home.dir");
%>
<html:outputLabel value="Répertoire de configuration: " />&nbsp;&nbsp;
<html:inputText value='<%=property%>'/>

</html:form>
</core:view>

无论是使用双引号还是什么都不起作用请问这个问题如何解决?非常感谢

最佳答案

问题出在这行代码上:

<html:inputText value='<%=property%>'/>

JSF 使用表达式语言向 JavaBean 填充值或从 JavaBean 读取值。您必须使用变量 property 创建一个 POJO 操作(称为 ManagedBean)并将其链接到那里。

例如

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;
}
}

不要忘记映射 ManagedBean。在 JBoss Seam 中,您只需在类上方添加一个 @Name 注释,例如 @Name("configurationAction")

最后,使用表达式语言 (EL) 在 JSF 中呈现此内容

<html:inputText value="#{configurationAction.property}"/>

其中 configurationAction 是 ManagedBean 的名称,property 是 ManagedBean 的实例。

关于inputText中的java代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7229194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com