Facelets: enable and disable attributes of a component inside a facelets component
Andres Guerrero
Greenhorn
Joined: Sep 22, 2008
Posts: 9
posted
0
Hi, I have a component similar to this one:
where the attribute disabled is only set when is not empty, it works fine, but when the component is re-rendered with an ajax request using a4j, doesn't work, the value attribute remains the same, because c:if is not a jsf component and doesn't take part of the jsf tree, I've tried <f:attribute ... rendered=""> but that attribute is ignored, any idea?, an alternative to f:attribute for adding and removing attributes to a component dinamically?
It's a Bad Thing to try and put logic on a JSF View. JSF is a fairly complete implementation of MVC, and in MVC, the display-related logic goes in the Controller (for JSF, that's mostly tag implementations) and the business-related logic attaches to the Model.
You're fighting the paradigm, so you can expect it to be less than co-operative. What you need to do is simplify your page - get rid of the JSTL altogether. Reference the backing bean for data and render values. The framework's designed to work that way and it will give much better - and more reliable - results.
Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Originally posted by Andres Guerrero:
Really odd code. Why don't you just do
[ December 17, 2008: Message edited by: Bauke Scholtz ]
Hi Bauke, thanks for your reply, finally the solution was:
thanks again
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
What was wrong with my proposed solution that you choose this approach?
Andres Guerrero
Greenhorn
Joined: Sep 22, 2008
Posts: 9
posted
0
Hi Bauke, I have many jsf pages that uses the normal inputText, now I have to add some functionality to some input fields doing a custom facelet component that must replace seamlessly those inputText tags, and should accept the same attributes;
For example, a component:
is replaced with:
The problem with the solution:
is that the result will be:
becuase disabled comes not empty.
Regards,
Andres
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Uhmm OK. There's a nasty bug somewhere in your custom component.
Anyway, glad you "fixed" it though. Good luck further.
Andres Guerrero
Greenhorn
Joined: Sep 22, 2008
Posts: 9
posted
0
Hi Bauke, I mean using:
that was what you suggested me, the result will be:
If the attribute disable is not empty, por example with value disable='false'
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
I assumed your 'disabled' variable as being an array or collection because of the use of the 'empty' keyword.
Better use disabled="#{disabled == 'true'}" or so if it is a String. More better is to just make it a boolean. This way you just need to do disabled="#{disabled}".
Andres Guerrero
Greenhorn
Joined: Sep 22, 2008
Posts: 9
posted
0
Hi Bauke, I found this in the Sun's EL Tutorial (URL):
Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
Thats why I used 'empty' in that way, I guess #{disabled == 'true'} will return false no matter if disabled is null, I will try your suggestion.
Regards,
Andres
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Yes I know that. But I keep guessing as long as you don't tell what type ${disabled} actually represents and what values it actually can hold. It's just because of the odd EL syntax you used.
If a type can hold only two values, why not just use boolean? [ December 19, 2008: Message edited by: Bauke Scholtz ]
Andres Guerrero
Greenhorn
Joined: Sep 22, 2008
Posts: 9
posted
0
The values of the attribute of the facelet componente can be anything, if the tag receives:
<x:anyComponent attributename="hello" />
Inside the component the variable is accessed with the variable:
#{attributename}
I don't know the way to "cast" or whatever that value to boolean, is just the text that the programmer type inside the value of the attribute.
Anyway thanks for your help [ December 19, 2008: Message edited by: Andres Guerrero ]
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Ahh, I see. You simply don't have direct control over that value. Okay then