3

There's an input element and I want to update it once the user enters something in there.

input element:

<h:form id="form">
    <h:inputText value="#{message.message}"> 
        <f:ajax event="keyup" render="form:compElem"/> 
    </h:inputText> 
    <compositeOutputComponents:test2 id="compElem" message="#{message.message}"/>
</h:form>

and this is how my composite element looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:composite="http://java.sun.com/jsf/composite">
  <h:head>
  </h:head>
    <h:body>
            <fieldset>
                <composite:interface>
                    <composite:attribute name="id"/>
                    <composite:attribute name="message" required="true"/>
                </composite:interface>
                <composite:implementation>
                    <span id="#{cc.attrs.id}">
                        <h:outputText value="#{cc.attrs.message}"/>
                    </span>
                </composite:implementation>
            </fieldset>
    </h:body>

I tried to pass id to the composite element as Balus in JSF Updating Composite Component (Primefaces) suggested (I dont use primefaces), but still page yields an error : "malformedXML: During update: form:compElem not found". When i use non composite element everything works fine.

Community
  • 1
  • 1
Benas
  • 2,106
  • 2
  • 39
  • 66
  • The error message contradicts with the code. The code contains the wrong render ID, but the error message shows the right render ID. What is it now? – BalusC Aug 28 '13 at 13:19

1 Answers1

3

You need #{cc.clientId} instead of #{cc.attrs.id} in the composite implementation.

<span id="#{cc.clientId}">

Otherwise it will end up as <span id="compElem"> instead of <span id="form:compElem"> and then JavaScript can't find it anymore, resulting in this malformedXML error.

Once you fix that part, then you can just reference it in <f:ajax render> the usual way like as you would reference any other non-composite component in the same form:

<f:ajax ... render="compElem" />

or if you insist in specifying absolute client IDs for some reason (but this is thus unnecessary):

<f:ajax ... render=":form:compElem" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • It's not clear for me where `cc.clientId` and `compElem` come from. Afaik `cc.clientId` is a placeholder for the `id` attribute assigned to the composite component element (when it's used) (assigned by the user or JSF). `compElem` is an example for an `id` chosen by the composite component creator, right? https://stackoverflow.com/questions/8412914/how-to-reference-cc-clientid-in-ajax-update-process-render-execute explains it better imo. – Kalle Richter Apr 12 '18 at 19:28
  • @Karl, as usual, the "See also" links contain further explanation. – BalusC Apr 12 '18 at 20:02