简体   繁体   中英

Java Server Faces Ajax request doesn't work properly

I use OpenFaces library and I want to execute some ajax request eg if checkbox is true display TextArea , but it doesn't work at all. The principle of operation is the same as in JSF standard lib. I will show You my code:

<o:selectBooleanCheckbox id="addOpis" value="#{ajaxBean.opis}">
    <o:ajax event="click" execute="addOpis" render="opisArea"/>
</o:selectBooleanCheckbox> 
<h:outputLabel for="dodajOpisCheckbox" value="zaznacz aby dodać opis" />
<o:inputTextarea id="opisArea" value="#{productBean.opis}" rendered="#{ajaxBean.opis}"/>

ManagedBean source:

@ManagedBean(name="ajaxBean")
@RequestScoped
public class AjaxBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private boolean opis;

    public AjaxBean() {
    }

    public void setOpis(boolean opis) {
        this.opis = opis;
    }

    public boolean isOpis() {
        return opis;
    }

}

I looked for some solutions but my code it seems to be good, please help.

There are no element with id opisArea on page after loading, because rendered attribute is false at default.

The most easy way to fix it - put opisArea inside of element, which always would be rendered:

<h:selectBooleanCheckbox id="addOpis" value="#{testBean.opis}">
    <f:ajax event="click" execute="addOpis" render="opisArea"/>
</h:selectBooleanCheckbox> 
<h:outputLabel for="dodajOpisCheckbox" value="zaznacz aby dodać opis" />
<h:panelGroup id="opisArea" >
    <h:inputTextarea value="#{productBean.opis}" rendered="#{testBean.opis}"/>
</h:panelGroup> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM