在不使用 passthrough atts 的情况下获取 bean 中 HTML 输入的内容
Get the content of an HTML input in a bean without using passthrough atts
我正在使用 javascript 在编辑器中转换 textArea(primefaces 编辑器不够可定制化)。
所以我有这个代码:
<textarea name="editor1" id="editor1" rows="10" cols="80" >
</textarea>
<script>
CKEDITOR.replace( 'editor1');
</script>
我想获取托管 bean 中文本区域的内容。
我没能让它与 inputTextarea 的 jsf 标签一起使用。
编辑:我猜它不起作用,因为使用时 ID 不一样
<h:inputTextarea id="editor1"/>
这将导致 id 如下:
j_tid53:editor1
我也试过这个:
xmlns:jsf="http://xmlns.jcp.org/jsf"
...
jsf:value="#{bean.property}"
但它会是 null
编辑:
我的 xhtml 命名空间:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
面孔配置:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
并且当服务器在控制台中启动时:
Initializing Mojarra 2.2.9 (-SNAPSHOT 20141218-0939 https://svn.java.net/svn/mojarra~svn/tags/2.2.9@14083) for context
那么我怎样才能得到我的 textArea 的内容呢?
由于 ID 错误,脚本无法运行。我只需要给表单一个 id 这样的:
<h:form id="form">
<p:inputTextarea value="#{newThread.title}" cols="98" rows="1">
<f:passThroughAttribute name="placeholder" value="#{miscellaneous.Title}"/>
</p:inputTextarea>
<p:inputTextarea id="sup"></p:inputTextarea>
<script>
CKEDITOR.replace( 'form:sup');
</script>
<p:commandButton value="#{miscellaneous.Submit}" action="#{newThread.sendNewThread}">
</p:commandButton>
</h:form>
问题是我不知道如何获取值。所以我切换到primeface extension。
这些是所需的依赖项:
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>resources-ckeditor</artifactId>
<version>3.1.0</version>
</dependency>
那么xhtml文件中的命名空间:
xmlns:pe="http://primefaces.org/ui/extensions"
和here is a link that explains step by step.
我正在使用 javascript 在编辑器中转换 textArea(primefaces 编辑器不够可定制化)。
所以我有这个代码:
<textarea name="editor1" id="editor1" rows="10" cols="80" >
</textarea>
<script>
CKEDITOR.replace( 'editor1');
</script>
我想获取托管 bean 中文本区域的内容。 我没能让它与 inputTextarea 的 jsf 标签一起使用。
编辑:我猜它不起作用,因为使用时 ID 不一样
<h:inputTextarea id="editor1"/>
这将导致 id 如下:
j_tid53:editor1
我也试过这个:
xmlns:jsf="http://xmlns.jcp.org/jsf"
...
jsf:value="#{bean.property}"
但它会是 null
编辑:
我的 xhtml 命名空间:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
面孔配置:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
并且当服务器在控制台中启动时:
Initializing Mojarra 2.2.9 (-SNAPSHOT 20141218-0939 https://svn.java.net/svn/mojarra~svn/tags/2.2.9@14083) for context
那么我怎样才能得到我的 textArea 的内容呢?
由于 ID 错误,脚本无法运行。我只需要给表单一个 id 这样的:
<h:form id="form">
<p:inputTextarea value="#{newThread.title}" cols="98" rows="1">
<f:passThroughAttribute name="placeholder" value="#{miscellaneous.Title}"/>
</p:inputTextarea>
<p:inputTextarea id="sup"></p:inputTextarea>
<script>
CKEDITOR.replace( 'form:sup');
</script>
<p:commandButton value="#{miscellaneous.Submit}" action="#{newThread.sendNewThread}">
</p:commandButton>
</h:form>
问题是我不知道如何获取值。所以我切换到primeface extension。
这些是所需的依赖项:
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>resources-ckeditor</artifactId>
<version>3.1.0</version>
</dependency>
那么xhtml文件中的命名空间:
xmlns:pe="http://primefaces.org/ui/extensions"
和here is a link that explains step by step.