File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Similar  logic:notPresent  in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Similar  logic:notPresent  in JSF" Watch "Similar  logic:notPresent  in JSF" New topic
Author

Similar logic:notPresent in JSF

Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 213
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

Moving to our brand new JSF Forum...


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Apr 10, 2003
Posts: 213
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

Check my post again. It wasn't showing up but it is there now.
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 213
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Apr 10, 2003
Posts: 213
Do I need to delcare renderHello as a managed property in faces-config.xml?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Apr 10, 2003
Posts: 213
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

Joined: Apr 10, 2003
Posts: 213
Hi Gregg,

according to the rendered attribute :

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

Thanks
Benson
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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 ]

- Varun
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: May 30, 2002
Posts: 1400
Oh, so that's implementation dependant, strange !!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: May 30, 2002
Posts: 1400
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

Joined: Apr 10, 2003
Posts: 213
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

Joined: May 30, 2002
Posts: 1400
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Apr 10, 2003
Posts: 213
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

Joined: May 30, 2002
Posts: 1400
you are right, there isn't any need. Just declaring it as a managed bean's would do it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Similar logic:notPresent in JSF