Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jsf。如何将backbean对象从jsf表单发布到javascript_Java_Javascript_Json_Jsf_Primefaces - Fatal编程技术网

jsf。如何将backbean对象从jsf表单发布到javascript

jsf。如何将backbean对象从jsf表单发布到javascript,java,javascript,json,jsf,primefaces,Java,Javascript,Json,Jsf,Primefaces,我将Primefaces/JSF与纯javascript工具结合使用,以实现图像查看器和注释器。图像查看器是基于 当用户在画布上注释(绘制形状)时,将创建一个JSON对象,并在保存操作时传递给backbean。backbean检索对象(反序列化)并将其存储到文件中 以下是相关代码: OpenLayers javascript(image viewer.js): 上面的Image Viewer/Map工具通过primefaces的p:outputPanel组件加载,并使用sendJSONToSer

我将Primefaces/JSF与纯javascript工具结合使用,以实现图像查看器和注释器。图像查看器是基于

当用户在画布上注释(绘制形状)时,将创建一个JSON对象,并在保存操作时传递给backbean。backbean检索对象(反序列化)并将其存储到文件中

以下是相关代码:

OpenLayers javascript(image viewer.js):

上面的Image Viewer/Map工具通过primefaces的p:outputPanel组件加载,并使用sendJSONToServer remoteCommand获取JSON层:

<h:head>
    <script src="#{facesContext.externalContext.requestContextPath}/js/image-viewer.js" />
    ...
    <h:body>
        <h:form id="imageEditor">
            <p:fieldset legend="Viewer">
                ...
                // inoutHidden does not have on* events? how am i going to post to image-viewer.js?
                <h:inputHidden value="#{imageAnnotations.fetchJsonString()}" />
                ...
                <p:outputPanel layout="block" styleClass="imageEditorImagePanel" />
                <p:remoteCommand immediate="true" name="sendJSONToServer" action="#{imageAnnotations.actionOnString}" />
            </p:fieldset>
        ....

问题是我将如何使用JSF或primefaces元素来提供imageAnnotations.fetchJsonString()值以从js中获取?

即使我不能给出所有答案,对我来说,您的
hiddenInput的填充应按以下方式管理:

@ManagedBean(name="imageAnnotations")
public class ImageAnnotations  {

    private String jsonString;

    public void anyMethodFillingOrInitializingTheJSONString() {
        this.jsonString = resultOfYourWork();
    }

    public String getJsonString(){
        return this.jsonString();
    }

    public void setJsonString(String item) {
        this.jsonString = item;
    }
}
重新加载此隐藏输入字段时,请确保触发javascript解析字符串并更新客户端模型。这可以通过可与Primefaces按钮连接的on*-事件来完成

伙计们,有人能帮我做其他部分吗

@ManagedBean(name="imageAnnotations")
public class ImageAnnotations  {

    //actionOnString fetches and saves the JSON string - this is a raw impementation
    public String actionOnString() {
        //Do the job and get and save JSON string
    }

    public String fetchJsonString(){
        //Do the job and get JSON string
        return jsonString;
    }
}                
@ManagedBean(name="imageAnnotations")
public class ImageAnnotations  {

    private String jsonString;

    public void anyMethodFillingOrInitializingTheJSONString() {
        this.jsonString = resultOfYourWork();
    }

    public String getJsonString(){
        return this.jsonString();
    }

    public void setJsonString(String item) {
        this.jsonString = item;
    }
}