JSF 2.0,malformedXML在commandlink使用Ajax时JSF、malformedXML、Ajax、commandlink

由网友(葬)分享简介:我想通过commandlink.However一个Ajax请求后显示在表单字段,我得到一个malformedXML错误,当我点击链接。该XHTML文件是这样的:I am trying to display a field in a form after an ajax request through a comman...

我想通过commandlink.However一个Ajax请求后显示在表单字段,我得到一个malformedXML错误,当我点击链接。该XHTML文件是这样的:

I am trying to display a field in a form after an ajax request through a commandlink.However ,i get a malformedXML error when i click the link. The xhtml file looks like :

            <h:form>    
                .
                .
                <tr>
                    <td>Product Image*:</td>
                    <td>
                        <h:graphicImage url="#{addItem.prodFileName}" width="100" height="100"/>
                        <br /><h:commandLink  value="change image" >
                            <f:ajax event="click" render="uploadimage" execute="@this" listener="#{addItem.ChangeImage}"/>
                        </h:commandLink>
                    </td>
                </tr>

                <tr >
                    <td>
                        <t:inputFileUpload rendered ="#{addItem.editImgChange}" label="editImage" id="uploadimage" value="#{addItem.uploadedFile}" />
                        <h:messages for="prodimage"/>
                    </td>
                </tr>
                .
                .
            </h:form>

本的AddItem bean是RequestScoped它具有以下线的code:

The AddItem bean is RequestScoped and it has the below lines of code:

    @ManagedBean
    public class AddItem extends AbstractBean {
        //..
    boolean editImgChange=false;
        //...           
    public void ChangeImage(){
    this.editImgChange=true;
        }
    }

Inshort,我想显示T:用户点击更改图像链接后,才inputFileUpload领域。我一直在的AddItem豆,其初始值是假的,一旦用户点击了变化图像链接,该标志更改为true一个标志editImgChange。该程序将进入ChangeImage()方法,但在那之后我得到的错误

Inshort,i want to display the t:inputFileUpload field only after user clicks the change image link. I have kept a flag editImgChange in the AddItem bean whose initial value is false and once user clicks the change image link ,the flag is changed to true. The program goes to the ChangeImage() method ,but after that i get the error

malformedXML:在更新:j_idt30:uploadimage找不到

"malformedXML:During update:j_idt30:uploadimage not found"

我会很乐意与一个完全不同的解决方案,同时,要达到同样的效果,柜面我的设计是坏的。

I will be happy with a totally different solution also, to achieve the same result ,incase my design is bad.

推荐答案

渲染属性应指向它总是呈现到HTML组件的ID。这就是JavaScript的谁应该基于Ajax响应更新/更换的内容。但是,如果将组件从未呈现成HTML,然后JavaScript的将不能够更新/更换其内容。你需要把它包在它总是呈现为HTML另一个组件,然后,而不是更新它。

The render attribute should point to the ID of a component which is always rendered into the HTML. It's namely JavaScript who is supposed to update/replace its content based on the ajax response. But if the component is never rendered into HTML, then JavaScript won't be able to update/replace its content. You need to wrap it in another component which is always rendered into HTML and then update it instead.

例如。

<h:panelGroup id="uploadimage">
    <t:inputFileUpload rendered ="#{addItem.editImgChange}" label="editImage" value="#{addItem.uploadedFile}" />
</h:panelGroup>
阅读全文

相关推荐

最新文章