Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Similar logic:notPresent in JSF

 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I usually use struts to develop front-end applications. Recently, I am quite interested in JSF and want to know how similar to struts it is.

When I study JSF, I cannot find the tag which is similar to <logic:notPresent> tag in struts. If you know there is similar things in JSF, please let me know.


Thanks
Benson
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our brand new JSF Forum...
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that JSF is component oriented. So you turn components on and off. Basically you can use the rendered attribute. So you might have something like:




And then in your backing bean:



[ January 07, 2005: Message edited by: Gregg Bolinger ]
[ January 07, 2005: Message edited by: Gregg Bolinger ]
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gregg, so how is the corresponding JSP fragment in order to work with these two bean method?


Thanks
Benson
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check my post again. It wasn't showing up but it is there now.
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

according to the rendered attribute :

rendered="#{backingbeans.renderHello}", the JSF will will isRenderHello or getRenderHello ?

Is it equivalent to the following JSP fragment?

<h utputText value="Hello" binding="#{backingbeans.renderHello}" rendered="false"/>


Thanks for your help actually.

Benson
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The binding and rendering attributes do 2 totally different things. The binding attribute binds the HTML compontent to an actual object in the backing bean. The rendered attribute simply tells JSF whether or not to display the component. It only takes true or false.

When speaking about booleans, it is the same in any JavaBean. Booleans aren't get and set. They are is and set. You don't "get this boolean". You say "is this boolean".
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I need to delcare renderHello as a managed property in faces-config.xml?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Benson Fung:
Do I need to delcare renderHello as a managed property in faces-config.xml?


Nope. Just in your backing bean.

private boolean renderHello;
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

What is the difference between declaring the property in faces-config.xml or not?

I am very confused.


Thanks
Benson
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

according to the rendered attribute :

rendered="#{backingbeans.renderHello}", the JSF will call isRenderHello or getRenderHello ?

Thanks
Benson
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a property "renderHello", irrespective of it's type I have to use getRenderHello() (not isRenderHello() ) to retrieve in JSF page.

Does "isRenderHello" works for you Gregg?
[ January 07, 2005: Message edited by: K Varun ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Varun:
If I have a property "renderHello", irrespective of it's type I have to use getRenderHello() (not isRenderHello() ) to retrieve in JSF page.

Does "isRenderHello" works for you Gregg?

[ January 07, 2005: Message edited by: K Varun ]


Yes, is works fine for me.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, so that's implementation dependant, strange !!
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Varun:
Oh, so that's implementation dependant, strange !!


I don't see why it would be. What implementation are you using? The other thing is using isXXXX for booleans is just general JavaBean rules.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:


I don't see why it would be. What implementation are you using? The other thing is using isXXXX for booleans is just general JavaBean rules.


I am using IBM's jsf implmentation.
If I create a boolean xxx property, the IDE create isXXX method automatically, so far so good .... but to use it in UI page, I have to change that isXXX to getXXX, else I face the error "property not found"
[ January 07, 2005: Message edited by: K Varun ]
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

What is the difference between declaring the property in faces-config.xml or not?

I am very confused.


Thanks
Benson
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example of a property (id) configured in faces-config.xml

So in this case, you are initializing "id" variable of your session scoped bean with some other request scoped bean's attribute.

Also, you can configure a dBHandler managed bean class with some "configurable" values of dbUserId, dbUserPW, MaxConnections etc.

Similarly, there are many other benefits, I hope you've must got the basic point.
[ January 07, 2005: Message edited by: K Varun ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Varun:


I am using IBM's jsf implmentation.
If I create a boolean xxx property, the IDE create isXXX method automatically, so far so good .... but to use it in UI page, I have to change that isXXX to getXXX, else I face the error "property not found"

[ January 07, 2005: Message edited by: K Varun ]


That's messed and a bad implementation IMO.
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Varun,

How about like this?

<managed-bean><managed-bean-name>someSessionBean</managed-bean-name><managed-bean-class>somepackage.someSessionBean</managed-bean-class><managed-bean-scope>session</managed-bean-scope><managed-property><property-name>id</property-name>
<property-class>String</property-class>
</managed-property>
</managed-bean>

In this fragment, why I need to declare in faces-config.xml and specify its class type?


Thanks
Benson
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right, there isn't any need. Just declaring it as a managed bean's would do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic