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 Using the rendered attribute nulls my value related backing bean variable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Using the rendered attribute nulls my value related backing bean variable." Watch "Using the rendered attribute nulls my value related backing bean variable." New topic
Author

Using the rendered attribute nulls my value related backing bean variable.

Richard Blaha
Ranch Hand

Joined: Dec 13, 2007
Posts: 34
I am a Greenhorn to JSF and have been battling my way through learning how to use it and produce a Production product at the same time. I have been using JavaServerFaces IN Action by Kito D. Mann. Apparently I cannot right off find anything with more explanation than is found on page 148 (4.2 Common Component properties). Also, Google and Bing searchs bring up some information, but does not seem to addres my particular concern.


I am working with a series of comments of which I can have up to ten levels. The first level (0 based) is always displayed, but the other nine levels (1-9) I want to not be rendered as visible until that level is reached. The following is a snippet of code reflecting what I am attempting. The example has backing bean: level. The 'comment1' and 'name1' fields both have getters and setters in the 'level' backing bean.


<h:panelGrid columns="2" border="0" cellpadding="2" cellspacing="0" rendered="#{level.level >= 1}" >
<h:inputText id="comment1" value="#{level.coment1}" title="COMMENT ONE" readonly="#{level.level > 1}" />
<h:inputText id="name1" value="#{level.name1}" title="NAME ONE" readonly="#{level.level > 1}" />
</h:panelGrid>


This works great for not displaying this particular panelGrid when the level is 0. And the readonly works great for levels above 1 in this example. But when the level is 1 and the screen is submitted whatever has been entered on the screen in the 'comment1' and 'name1' fields is returned as 'null' instead of what has been entered for the comment and name.

What am I missing? What have I not learned yet? Can someone point me to an explanation on how to use this?


Thank you.

rdb
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Is this component embedded in a JSF form?


Customer surveys are for companies who didn't pay proper attention to begin with.
Richard Blaha
Ranch Hand

Joined: Dec 13, 2007
Posts: 34
Tim, thank you for your response. Yes it is. I have quite a bit of other information prior to my comment section. To be accurate I have:

<h:form>
<%-- a lot of input information is collected here --%>
<h:panelGroup >
<%-- the code given in original post --%>
</h:panelGroup >

<h:commandLink action="#{level.edit}" value="Save">
<f:param name="jsfcrud.currentLevel" value="#{jsfcrud_class['com.company.jsf.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][level.level][level.converter].jsfcrud_invoke}"/>
</h:commandLink>
</h:form>

Also, in the original post if all I do is remove the rendered paramter I can retrieve the value without any problem.

I am using Netbeans 6.7.1 as my IDE for generating the initial JSF web pages/backing beans/etc.

rdb
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Hmmm. Is the scope of the "level" bean "request"? If so, try "session". Or, if you're using JSF2 "view".

Hint: you can make code and XML more readable if you use the message editor's "Code" button.
Richard Blaha
Ranch Hand

Joined: Dec 13, 2007
Posts: 34
In the faces-config.xml the <managed-bean-scope> was set to 'session'. When I put in 'view' I received the following error from the Glassfish server:

Value 'view' is not facet-valid with respect to enumeration '[request, session, application, none]'. It must be a value from the enumeration.

rdb
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

That means you don't have jsf2 support. Use session scope, instead.
Richard Blaha
Ranch Hand

Joined: Dec 13, 2007
Posts: 34
Thanks for your direction so far. Where do I go from here? Sounds like a sticky wicket right now.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Richard Blaha wrote:Thanks for your direction so far. Where do I go from here? Sounds like a sticky wicket right now.


For that you might want to talk to some local experts. Sometimes it's easier to tell when you can go "hands-on".
Richard Blaha
Ranch Hand

Joined: Dec 13, 2007
Posts: 34
The answer lies somewhere in my production code. I just wrote a quick webapp to test using a tutorial database table and the rendered parameter appears to work as described. Now to find the difference between my test code and my production code. Not sure where to look or what to look for.
 
Don't get me started about those stupid light bulbs.
 
subject: Using the rendered attribute nulls my value related backing bean variable.