【发布时间】:2012-01-21 23:13:49
【问题描述】:
我的页面中有一个 CKEditor。像这样
<h:head>
<title>Facelet Title</title>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script language="JavaScript">
function comeBack(){
document.getElementById(editorValue).value = this.value;
}
</script>
</h:head>
<h:body >
<h:form id="ckEditorForm" prependId="false" >
<textarea id="editor1"
name="editor1"
onblur="alert(document.getElementById(editorValue).value = this.value);">
</textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>
<h:inputHidden value="#{editorBean.value}" id="editorValue" />
<h:commandButton id="submit"
value="Submit"
action="welcome.xhtml" />
</h:form>
</h:body>
@ManagedBean
@ViewScoped
public class EditorBean {
private String value;
/** Creates a new instance of EditorBean */
public EditorBean() {
} //end of constructor
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
System.out.println("Content: "+value);
System.out.println();
}
} //end of class EditorBean
现在我希望该用户按下提交按钮,然后将编辑器值保存到我的 bean 中。我在这个论坛上发现了有人建议的这种隐藏域技术,但它不起作用。难道我做错了什么?我怎样才能达到我想要的?
谢谢
【问题讨论】:
-
也许您可以编写自己的复合 JSF 组件,在客户端使用 CKEDITOR?这是一个关于如何编写复合组件的好教程。 mkyong.com/jsf2/composite-components-in-jsf-2-0
标签: javascript html jsf-2