-
1. Re: conditional attribute in RichFaces CDK template (custom component)
nbelaevski Jan 31, 2010 5:35 AM (in response to looseleaf)Hi Stefan,
You can do the following:
1) define method in abstract renderer class:
public boolean isComponentDisabled(UIComponent component) { return getUtils().isBooleanAttribute(component, "disabled"); }
2) create variable in scope:
<c:object var="disabled" type="boolean" value="#{this:isComponentDisabled(component)}" />
3) use this variable in template:
<input ... disabled="#{disabled}" />
-
2. Re: conditional attribute in RichFaces CDK template (custom component)
looseleaf Jan 31, 2010 7:39 AM (in response to nbelaevski)Servus Nick!
I'm afraid, I can't. Try this in your favourite browser:
<input type="text" disabled="false">
<input type="text" disabled="true">You'll see that both of them are disabled. I can't recall or find the spot in the HTML specification, but the value of the disabled attribute is irrelevant. If the attribute is there, the control is disabled. So this is not viable.
Although your posting offers some good hints as to using other methods for other problems
Is there a way to dynamically define an HTML entity?
Edit:
I guess, I could introduce a method that returns the whole disabled-String, like this
{code:Java}
public boolean getComponentDisabledString(UIComponent component) {
if (getUtils().isBooleanAttribute(component, "disabled")) {return "disabled='disabled'";
} else {
return "";
}
{code}
Edit #2:
Nope, also gives an XML parsing error when using
<input type="text" #{disabledstring} value="..." />
Of course.
Thanks so far,
Stefan
p.s.: How can I post here with Opera? The AJAX-Editor does not provide any "unsupported browser" or non-JS fallbacks.
-
3. Re: conditional attribute in RichFaces CDK template (custom component)
nbelaevski Jan 31, 2010 7:45 AM (in response to looseleaf)Right, I see now that CDK correctly handles boolean properties only in encoding of pass-through attributes.
Then the following changes should be done:
1) <cdk:object> should be declared with java.lang.String type
2) method code:
public String getComponentDisabledString(UIComponent component) {
if (getUtils().isBooleanAttribute(component, "disabled")) { return "disabled"; } else { return null; }
}Attributes with empty strings/null values are not rendered.
P.S. About Opera: https://jira.jboss.org/jira/browse/ORG-373
-
4. Re: conditional attribute in RichFaces CDK template (custom component)
looseleaf Jan 31, 2010 8:14 AM (in response to nbelaevski)Naah, doesn't work, not een with returning null if the component is not disabled.
[cdk:generate]
Parse config file ...\src\main\config\component\inputTN[cdk:generate]
[Fatal Error] :24:14: Element type "input" must be followed by either attribute specifications, ">" or "/>".So the XML parser does not accept the #{disabledstring} text within the <input> element, like I wrote in the second edit for my last posting.
Any other ideas?
-
5. Re: conditional attribute in RichFaces CDK template (custom component)
nbelaevski Jan 31, 2010 8:36 AM (in response to looseleaf)Try:
<input type="text" disabled="#{disabled}" />
with the method code I've posted.
-
6. Re: conditional attribute in RichFaces CDK template (custom component)
looseleaf Jan 31, 2010 9:16 AM (in response to nbelaevski)Ah, I missed that point completely.
Thanks very much for your help!
Stefan