Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can ActionListener modify some UIComponent?  RSS feed

 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everyone!
I am trying to create a sort of filter to make pages read-only under some circumstances. So I created an ActionListener for this. Everything seems to work: the listener is called, it takes all of the current UIViewRoot's children and sets the disabled property to true wherever it can be done. But when the page is rendered again the components (inputText, selectManyCheckbox and so on) are not disabled.
Maybe I thought wrong, maybe I just cannot do this sort of thing in the ActionListener. If so, how can I do it? Binding a quarter of my application's buttons does not seem feasible. Suggestions?
 
Dave Boyd
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your approach should be fine

but instead of binding your components why not bind the disabled property

i.e <h:inputText ... disabled="#{someBean.someProperty}"/>

have someProperty be true or false

that way all you have to do is change the someProperty variable in your bean to true and all yoru components are disabled

or set it to false and all yoru components are enabled


the structure you used should be fine i.e will work from action listener
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that it is just not working the way I did. I don't want to bind every disabled property because that would take maintaining over a thousand fields in dozens of pages. It is a lot better than binding the field, of course.
Could it be MyFaces' erroneous behavior?
 
Henry Lowell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would seem to me that the reason the rendered state is not, well, stateful, is because the managed bean is probably in the request scope therefor everytime you go to that page you can a new instance of your managed bean with all things new related.

You could put it in session scope, but if you feel the same way about that as I do, you won't. Another option, and one that I can mention but don't have the knowledge to help with is possible a phase listener that checks for some session property when hitting that page and renders all the fields appropriatly. But that may be more work than the reward. Just trying to through out some suggestions.
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! Now I sense some dark magic going on -- and I like it
Indeed, the managed bean is in request scope; but by the time the ActionListener is invoked isn't the request already rebuilt? I mean, is the request that is available at the ActionListener the same available for the action and the jsp page?
What about that phase listener? I think I am going to check that out first.
[ June 07, 2006: Message edited by: Henrique Sousa ]
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right, I tried dark magic (PhaseListener) approach. I created a PhaseListener and registered it for the RENDER_RESPONSE phase. This way I could get to the UIComponents before the JSP is rendered again, right? Apparently not. I disabled the fields in both beforePhase and afterPhase methods and nothing happened in the page. I am going to try the ultimate evil, Javascript, in order to keep this maintainable at some level.
Man, JSF is good but it can be such a pain sometimes
[ June 07, 2006: Message edited by: Henrique Sousa ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!