• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

"Fake" Dynamic Field to Form [using rendered]

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys...

I want to do the following:

A select one menu with fields names.
A button to add the field to the form.

BUT! The field is already there! But it was been "rendered" false to start with.
So, my idea is: when the user clicks on the add button, the method that handles the rendered boolean for each field
will then return TRUE, and the ajax update":form" should do the trick and make the field appear.
But didn´t work.

The front end with the select one menu.



Some fields are by default VISIBLE, so no rendered needed.

the methods on managedBean:



As you can see, I have an HASHMAP to control if that field is visible or not.

Did I do something wrong on the front end?
 
Saloon Keeper
Posts: 28718
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


#{grupoController.filterIsVisible(filterIdade)}



Is not good practice. You should not be coding parameters on the View if at all possible. Also, I'm not even sure that you can do a general method call in the context of a "rendered" attribute to begin with, Normally you should be making a property reference.

I also cannot make sense of what appears to be a possible page-scope variable "filterIdade". JSF does not support page scope at all. To function properly, "filterIdade" needs to be a property of a backing bean, not an independent entity.
 
Marco Noronha
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:


#{grupoController.filterIsVisible(filterIdade)}



Is not good practice. You should not be coding parameters on the View if at all possible. Also, I'm not even sure that you can do a general method call in the context of a "rendered" attribute to begin with, Normally you should be making a property reference.

I also cannot make sense of what appears to be a possible page-scope variable "filterIdade". JSF does not support page scope at all. To function properly, "filterIdade" needs to be a property of a backing bean, not an independent entity.



thanks for the answer.
Well... I got it running Tim.

You right about the bad pratices. But it works.
Maybe it should be an convencion for my project.

The correct xhtml looks like this:


 
Tim Holloway
Saloon Keeper
Posts: 28718
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"It works" isn't a happy phrase for me. It's often followed by "it broke". And "I haven't the faintest idea of how this ever worked". Or "We can't change that".

Here's a more JSF-friendly expression:


Note that I've changed "filterIsVisible" to a property referencing a Map<String, Boolean>, and made "grupo.idade" be a key into the map.

And, BTW. Backing beans are NOT Controllers. In JSF the Controllers are pre-supplied in the FacesServlet and in the tag internal implementations. Backing beans are Models. Listeners and Action methods are not Controller methods. Action methods, in fact, are business logic.
 
Marco Noronha
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:



Wow! That was very very good!
But I need a method on the backing bean because I use it on the java side as well.

Oh, I thought ManagedBean would be like an controller...
Basiclly i dont have a controller. Only Model and View on JSF
 
Tim Holloway
Saloon Keeper
Posts: 28718
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The backing bean method is:


So the Java usage would be:


However, "magic" values are not considered ideal even in pure Java code, much less on View Definitions, so it might be better to do this:



You would then be a able to invoke that method directly in Java code and you would also be able to simplify your View Template:


It's always desirable to keep the EL as simple as possible. Even if you don't subscribe to the the "No Logic In View Rule", debugging EL is a

In JSF, you do have Controllers. The difference is, you don't code them yourself (usually!). Most of the Controllers you need are already supplied.
 
Marco Noronha
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand.
But if I have a view with 50 fields ?

Wouldn´t be too 'manual' writing one method per field?
 
Tim Holloway
Saloon Keeper
Posts: 28718
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marco Noronha wrote:I understand.
But if I have a view with 50 fields ?

Wouldn´t be too 'manual' writing one method per field?



Probably. Then again, I think I probably would have used a dataTable for the display with a List or array model, and that would have allowed me to simply use indexing instead of complicated Map expressions.
 
Marco Noronha
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Marco Noronha wrote:I understand.
But if I have a view with 50 fields ?

Wouldn´t be too 'manual' writing one method per field?



Probably. Then again, I think I probably would have used a dataTable for the display with a List or array model, and that would have allowed me to simply use indexing instead of complicated Map expressions.



can you please show me an example of that working?
 
Tim Holloway
Saloon Keeper
Posts: 28718
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend looking at a good JSF book.
 
Marco Noronha
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I recommend looking at a good JSF book.



I read the Core JavaServer Faces Ed. 3.

Any other recomendations?


IT would be really nice of you, if you could
just show me am example
but I don´t want to make you lose your time..

So thanks anyway
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic