0

This is the xhtml part of my composite component:

    <cc:interface componentType="partnerSelComp">
        <cc:attribute name="value" type="java.lang.Long"/>            
        <cc:attribute name="disabled" type="java.lang.Boolean" default="#{false}"/>            
        <cc:attribute name="service"/>
    </cc:interface>

    <cc:implementation>
        <span id="#{cc.clientId}" style="white-space:nowrap">                                
            <p:inputText id="id" type="hidden" binding="#{cc.partnerId}"/>
            <p:inputText id="code" 
                         binding="#{cc.partnerCode}" 
                         disabled="#{cc.attrs.disabled}" >                     
                <p:ajax event="blur" update="code name msg" listener="#{cc.validate}" />                                                                                                    
            </p:inputText>            
            <p:inputText id ="name" 
                         disabled="true" 
                         binding="#{cc.partnerName}" />                   
            <p:message id="msg" for="code"/>                
        </span>
    </cc:implementation>

I call it this way:

<my:PartnerSelComp id="partnerSel" value="#{myBean.partner}" service="#{partnerService}" disabled="true"/>

When component rendered initially the code component appears editable event though disabled="true" specified. But after the first ajax blur event (I guess because the update) it will get the the correct disabled state. Querying it's value in backing component getAttributes().get("disabled") I can see the correct value. Why is it? How can I set initial appearance of the component?


I was able to fix it. I wouldn't say a solution rather a not too elegant workaround:

@Override
public void encodeAll(FacesContext context) throws IOException {

    Boolean b = (Boolean) getAttributes().get("disabled");
    partnerCode.setDisabled(b);
    super.encodeAll(context);
} 

I would be pleased if I could understand what is the problem with original one.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BgY
  • 83
  • 9

1 Answers1

-1

Try this,

 <cc:attribute name="disabled" type="java.lang.String" default="false"/>  

And replace :

<span id="#{cc.clientId}" style="white-space:nowrap"> 

by

<p:panel id="#{cc.clientId}" style="white-space:nowrap"> 
bilelovitch
  • 1,975
  • 1
  • 16
  • 24
  • Can you explain why you think this is the solution? – Kukeltje Jan 31 '17 at 11:25
  • for the cc:attribute, you do not need to complicate life with a Boolean value; the true | false string or boolean are same. For the p:panel you're using p:ajax so you need to update a jsf component not the html directly. – bilelovitch Jan 31 '17 at 12:44
  • Complicate or not, would it be a **problem** using a boolean? (and the downvote is not from me btw). And why is giving a `span` an id a problem? I'm not saying you are wrong, I'm trying to learn and getting more detailed information for others so they can learn as well – Kukeltje Jan 31 '17 at 12:57
  • When you want to disable an inputText you can always write disabled="false" or disabled="#{false}" but the first is simple. For jsf, there is a life cycle that is respected. The h or p tag is translated into HTML, so if you want to update the html directly you have to retrieve the final ID from the source code. – bilelovitch Jan 31 '17 at 13:13
  • Ok, so the first part is about 'beauty' (which is always in the eye of the beholder) But about the second part, are you sure: http://stackoverflow.com/questions/9726818/jsf-updating-a-composite-component – Kukeltje Jan 31 '17 at 13:21
  • Perhaps it's work in this case because p:panel is transformed to div – bilelovitch Jan 31 '17 at 14:11
  • I tried `p:panel` instead of `span` and `String` instead `Boolean` but there was no effect. Only `encodeAll` gave a workaround for it. – BgY Feb 01 '17 at 14:58