我正在使用primefaces pe:ckEditor进行html编辑器并使用自定义工具栏,它位于对话框架中。当pe:ckEditor打开时,它不能像我预期的那样工作。这是我的代码。
<h:form id="myBeanForm">
<!--other component-->
<p:commandButton value="button" action="#{myBean.openDialogFramework}" process="@this"/>
</h:form>
@ViewScoped
@ManagedBean
@Named("myBean")
public class MyBean{
@PostConstruct
public void init() {
//do something
}
public void openDialogFramework(){
Map<String,Object> options=new HashMap<String, Object>() {
{
this.put("height", 625);
this.put("width", 1280);
this.put("modal", true);
this.put("resizable", true);
this.put("contentWidth", "100%");
this.put("contentHeight", "100%");
}
};
Map<String, List<String>> params=new HashMap<>();
params.put(keyValue, new ArrayList<String>() {
{
this.add(jsonValue);
}
});
openDialog(dialogPath,options,params);
}
private void openDialog(String outcome, Map<String, Object> options, Map<String, List<String>> params) {
RequestContext.getCurrentInstance().openDialog(outcome, options, params);
}
}
<h:form id="myDialogBeanForm">
<pe:ckEditor id="ckEditor" width="100%" id="detailEditor" height="400"
toolbar="[['Cut','Copy','Paste','PasteText','-','Format','Font','FontSize','-',
'Bold','Italic','Underline','Strike','Subscript','Superscript','-','NumberedList','BulletedList','-',
'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl','-',
'TextColor','BGColor','-','Image','Link','Unlink','-','RemoveFormat']]"/>
</h:form>
@ViewScoped
@ManagedBean
@Named("myDialogBean")
public class MyDialogBean{
private Bean bean;
@PostConstruct
public void init() {
bean= getParam(keyValue);
}
private <T> T getParam(String key) {
HttpServletRequest request = (HttpServletRequest)
FacesContext.getCurrentInstance()
.getExternalContext().getRequest();
String beanJson= request.getParameter(key);
if (StringUtils.isEmpty(beanJson)) return null;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature
.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature
.FAIL_ON_IGNORED_PROPERTIES, false);
return mapper.readValue(beanJson, Bean.class);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
在这个例子中,当我单击按钮并打开对话框视图时,pe:ckEditor显示如下(只是没有):
如果我不使用自定义pe:ckEditor,这个问题就消失了;并且每次定制都不会发生。