-
1. Re: Disabling a group of input fields.
christian.bauer Oct 26, 2009 6:29 PM (in response to hubaer)<s:fragment rendered="true|false">...</s:fragment>
-
2. Re: Disabling a group of input fields.
hubaer Oct 27, 2009 9:16 AM (in response to hubaer)Thank you Christian for your reply.
But that was not the solution I was looking for. If I set rendered to true or false, I can show or hide some components. But I am looking for a solution to set a group of components in an editable or non editable state.Any further suggestions?
Regards
Marco -
3. Re: Disabling a group of input fields.
chris.simons Oct 27, 2009 3:10 PM (in response to hubaer)I don't know of any way that you can disable all
inner
components in one fell swoop like that; you could look into doing this via jQuery, however.Is there anything preventing you from just setting disabled="#{someValue}" on each component, individually?
-
4. Re: Disabling a group of input fields.
hubaer Oct 27, 2009 3:32 PM (in response to hubaer)Sure, I could set the disabled attribute at all input components. But for maintenance reason it would be better to have one panel where I can set this attribute, like the rendered attribute in s:fragement or other panels.
Regards
Marco -
5. Re: Disabling a group of input fields.
chris.simons Oct 27, 2009 3:50 PM (in response to hubaer)Agreed, it would be neat if there were a
formGroup
component wherein the children components could be qualified at this level (rendered, disabled, etc.).You could specify a jQuery function on the panel's onLoad or onChange, perhaps?
-
6. Re: Disabling a group of input fields.
kragoth Oct 28, 2009 12:25 AM (in response to hubaer)I think jQuery is most likely the easiest way to implement this.
But, if you don't like the idea of jQuery, then investigate making your own component to do this for you. I'm still thinking about how I would do it, as components that affect their children are fairly difficult to write... but not impossible.
My guess is something like this:
NOTE: This is not tested or even tried, just a guess from some of the stuff I've doneWrite a component say...
public UIInputRestrictionComponent extends UIFragment { private boolean componentsDisabled = false; public void encodeBegin(FacesContext context) { for (UIComponent component : this.getChildren()) { if (component instanceof UIInputText) { //Do one of these for each type of component ((UIInputText)component).setDisabled(componentsDisabled); } } super.encodeBegin(context); } }
This has not been compiled or tested or even put into an IDE, so there will be bugs/errors. I'm just putting out an idea that might be worth trying if this is the sort of behaviour you need in your app.
If anyone knows if this will not work for some reason please say so, cause I really don't know and don't really have the time to go work it out :P
Hope it helps.
-
7. Re: Disabling a group of input fields.
hubaer Oct 28, 2009 10:46 AM (in response to hubaer)Hello Tim,
thank you for your response. I was thinking about building a custom component, but hoping that there was a solution still outthere.
But thank you very much for your
prototype
code. I will try this out, this is a good starting point.Regards
Marco -
8. Re: Disabling a group of input fields.
cash1981 Oct 28, 2009 12:04 PM (in response to hubaer)Here is an example of a menu that is visible depending on security role.
Some are shared, some are only for officer, some only for admin.
Christian is right that the best thing is to use s fragment<ul xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib"> <s:fragment rendered="#{s:hasRole('officer')}"> <li class="#{menu_home?'active':''}"> <div><s:link propagation="none" view="/minesider.xhtml" title="#{messages['home']}" value="#{messages['home']}" /></div> </li> <li class="#{menu_admin?'active':''}"> <div><s:link propagation="none" view="/admin/officer/officer_admin.xhtml" title="#{messages['settings']}" value="#{messages['settings']}" /></div> </li> </s:fragment> <li class="#{menu_support?'active':''}"> <div><s:link propagation="none" view="/support.xhtml" title="#{messages['support']}" value="#{messages['support']}" /></div> </li> <s:fragment rendered="#{s:hasRole('orgadmin') or s:hasRole('sysadmin')}"> <li class="#{menu_admin?'active':''}"> <div><s:link propagation="none" view="/admin/admin.xhtml" title="#{messages['admin']}" value="#{messages['admin']}"/></div> </li> </s:fragment> <li> <div><s:link view="/home.xhtml" action="#{identity.logout}" value="#{messages['logout']}" title="#{messages['admin']}" rendered="#{identity.loggedIn}"/></div> </li> </ul>
-
9. Re: Disabling a group of input fields.
kragoth Oct 29, 2009 12:08 AM (in response to hubaer)Shervin, the original poster is not trying to control the 'visibility' of components. He is trying to control the readonly aspect. So the components will always be visible but, not necessarily editable.
Thus, the s:fragment will not actually do what is required.
Marco, if you do get the component working could you please post your code in this topic for the rest of us to see. :)
-
10. Re: Disabling a group of input fields.
cash1981 Oct 29, 2009 11:09 AM (in response to hubaer)All components have a disabled attribute. It shouldn't be any problem disabling them? They accept EL too, so you can even have some nice condition before disabling them.
Or you can do it onLoad with JavaScript (or using JQuery which makes it very easy).
I don't get what the big deal is? -
11. Re: Disabling a group of input fields.
cash1981 Oct 29, 2009 11:11 AM (in response to hubaer)<h:inputText value="#{someBean.myText} disabled="#{s:hasRole('admin')}" />
-
12. Re: Disabling a group of input fields.
hubaer Oct 29, 2009 11:22 AM (in response to hubaer)Hello Shervin,
I know how to disable one component, as your example show.
But I'm looking / working on a solution like:
<somecomponent disabled="\#{s:hasRole('admin')}> <h:inputText value="#{someBean.myText}" /> <h:inputText value="#{someBean.myText2}" /> <h:inputText value="#{someBean.myText3}" /> </somecomponent>
So that I have the same behaviour for all components inside the somecomponent.
Regards,
Marco -
13. Re: Disabling a group of input fields.
cash1981 Oct 29, 2009 11:29 AM (in response to hubaer)That is not possible. You will have to add the disabled statement on all the components you want disabled,
-
14. Re: Disabling a group of input fields.
hubaer Oct 29, 2009 2:01 PM (in response to hubaer)Hello Shervan,
maybe I'm a dreamer in the world of Java and JSF, but so far I know I can write Java classes with own functionalities, JSF compoenents with own functionalities. So why should this not be possible? As far I have investigated this problem there is no JSF component out there (what my initial posting asked), but as Tim suggested above it is possible to write such a component.
Regards,
MarcoP. S.: Wondering how the rendered attribute at a s:fragement could be impact the rendering behaviour of all inner components? :-)