我的页面中有一个CKEditor。像这样如何从JSF中的html组件向服务器发送数据
<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
现在我想,用户按下提交按钮,然后编辑值保存到我的豆。我发现这个论坛上的某个人暗示了这种隐藏领域技术,但它不起作用。难道我做错了什么?我怎样才能达到我想要的?
感谢
也许你可以编写自己的复合JSF组件在客户端使用CKEDITOR?这里是一个关于如何编写复合组件的好教程。 http://www.mkyong.com/jsf2/composite-components-in-jsf-2-0/ – 2011-12-16 12:18:05