wood burning stoves 2.0*
The moose likes JSF and the fly likes How to get a value of a text field or a bean member in a JSP tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "How to get a value of a text field or a bean member in a JSP tag?" Watch "How to get a value of a text field or a bean member in a JSP tag?" New topic
Author

How to get a value of a text field or a bean member in a JSP tag?

Efrat Bar-Nahum
Ranch Hand

Joined: Jan 19, 2006
Posts: 57
Hi,

I have a JSF page with 2 outputText fields.
I want the second one to appear only if the first has a certain value.

It should be something like:



But I don't know how to get a value of a JSF field, or a value of a java bean member in a JSP tag (that is not bind to a field in the page), like the example above.

Can anyone help me?
Thanks,
Efrat
Bagwan Mehrat
Ranch Hand

Joined: Jan 26, 2002
Posts: 119
It might not be the best practice when using JSF, but in that situation, I know you can do something like:

<jsp:useBean id="alarm" class="com.mycompany.ModuleBean" scope="session"/>

That will make the JSP look up the JSF managed bean object and give you direct access to it. You'd need to set the class and scope parameters to match what you have in your faces-config file. Or, you can even do it the messier way by writing a scriptlet that does the equivalent of the above.
Abhi Raj
Greenhorn

Joined: Sep 08, 2004
Posts: 7
Try this:


<h outputText value="#{msgs.alarmState}:"/
<h outputText id="alarmState" value="#{ModuleBean.alarmState}"/>

<h outputText value="#{msgs.mostSevereAlarm}:"
rendered=#{alarmState.value != 'OK'}" />
<h outputText id="mostSevereAlarm" value="#ModuleBean.mostSevereAlarm}"
rendered=#{alarmState.value != 'OK'}" />


I think it should work.
Efrat Bar-Nahum
Ranch Hand

Joined: Jan 19, 2006
Posts: 57
Thanks a lot, The rendering idea worked!
I rendered the bean value as follows:



Thanks again for the help,
Efrat
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
Since you're controling more than one component you might want to look into the <f:subview>

For example

<h outputText value="#{msgs.alarmState}:"/
<h outputText id="alarmState" value="#{ModuleBean.alarmState}"/>

<f:subview id="onAction" rendered="#{alarmState.value != 'OK'}">
<h outputText value="#{msgs.mostSevereAlarm}" />
<h outputText id="mostSevereAlarm" value="#ModuleBean.mostSevereAlarm}" />

</f:subview>

That way you don't need to put a render tag on ever item.
Efrat Bar-Nahum
Ranch Hand

Joined: Jan 19, 2006
Posts: 57
Great!
Thanks a lot for the tip.

Efrat
 
GeeCON Prague 2014
 
subject: How to get a value of a text field or a bean member in a JSP tag?