[英]JSF 2.0, malformedXML when using ajax on a commandlink
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. 我试图通过commandlink在ajax请求后显示表单中的字段。但是,当我单击链接时,我收到malformedXML错误。 The xhtml file looks like :
xhtml文件如下所示:
<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>
The AddItem bean is RequestScoped and it has the below lines of code: AddItem bean是RequestScoped,它有以下代码行:
@ManagedBean
public class AddItem extends AbstractBean {
//..
boolean editImgChange=false;
//...
public void ChangeImage(){
this.editImgChange=true;
}
}
Inshort,i want to display the t:inputFileUpload field only after user clicks the change image link. Inshort,我想只在用户点击更改图像链接后显示t:inputFileUpload字段。 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.
我在AddItem bean中保留了一个标志editImgChange,其初始值为false,一旦用户单击更改图像链接,该标志就会更改为true。 The program goes to the ChangeImage() method ,but after that i get the error
该程序转到ChangeImage()方法,但之后我得到错误
"malformedXML:During update:j_idt30:uploadimage not found"
“malformedXML:更新期间:找不到j_idt30:uploadimage”
. 。
I will be happy with a totally different solution also, to achieve the same result ,incase my design is bad. 我也会对一个完全不同的解决方案感到高兴,为了达到同样的效果,我的设计很糟糕。
The render
attribute should point to the ID of a component which is always rendered into the HTML. render
属性应指向始终呈现在HTML中的组件的ID。 It's namely JavaScript who is supposed to update/replace its content based on the ajax response. 它就是JavaScript,它应该根据ajax响应更新/替换它的内容。 But if the component is never rendered into HTML, then JavaScript won't be able to update/replace its content.
但是,如果组件永远不会呈现为HTML,那么JavaScript将无法更新/替换其内容。 You need to wrap it in another component which is always rendered into HTML and then update it instead.
您需要将其包装在另一个始终呈现为HTML的组件中,然后更新它。
Eg 例如
<h:panelGroup id="uploadimage">
<t:inputFileUpload rendered ="#{addItem.editImgChange}" label="editImage" value="#{addItem.uploadedFile}" />
</h:panelGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.