wood burning stoves*
The moose likes JSF and the fly likes Displaying a value in <h:outputText> when some event occurs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Displaying a value in <h:outputText> when some event occurs" Watch "Displaying a value in <h:outputText> when some event occurs" New topic
Author

Displaying a value in <h:outputText> when some event occurs

Avinash Bhat
Greenhorn

Joined: Feb 03, 2011
Posts: 12

Hi,

I have one requirement where when i click on the attribute i would like to create an action and display the same in OutputText.

Ex:

This is Attribute Description outputText :




The action should be for :






I am unable to get the text coming on outputText, when i click on the above attribute.


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

I am not sure what that is supposed to look like to the user.

However, your outputText element with ID "attributeTextdescription" has no value, so it's not going to display anything. I'm not sure, in fact that it will even generate the <span> element that is used to hold the CSS info for the outputText. So I'd recommend putting in a value="" attribute as a placeholder.

One thing that can help a lot when debugging JavaScript in a JSF page is if you take complex javascript and wrap it in a javascript function. For quick-and-dirty function definitions, you can put them in a construct like this:


The verbatim tags permit JSF to pass through their body unmodified. The CDATA ensures that the XML parser won't get confused if "magic" xml characters such as ">" or "'" appear in the javascript expressions.

That results in the much simpler column definition:



When you do this, you can set breakpoints and use your javascript debugger to see what's happening. Note that I got rid of the raw HTML <a> tag, since the onclick works just as well on the outputText element.

I think, actually that your problem is that you didn't put quotes around #{currentAttribute.name} in your element value assignment, which would generate code expecting #{currentAttribute.name} to be the name of a javascript variable instead of a literal value like you wanted. But the trick I just described will make it easier to debug.

Customer surveys are for companies who didn't pay proper attention to begin with.
Avinash Bhat
Greenhorn

Joined: Feb 03, 2011
Posts: 12

My XHTML looks something like this:




Java script:



Question:

When user clicks on the Attribute, I have a function in jsp file ( CMBrowserBean.java)  This must be called.
Function:




So here I want to pass the attribute clicked to this JSP file, and get the id of the attribute (attribute name) like shown above…

And that readAttribute(), returns the string,,,, I want to display back this returned string in another inputTextarea field.

Another inputTextarea field is this:




So basically:

When user clicks on the Attribute, it should go to JSP method, the returned value must be back to XHTML file and I will display that in inputTextArea.


How do I do this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Your terminology appears to be scrambled. You refer to something you call a "JSP file", but the sample is java code like I'd expect to find in a backing bean. If you're expecting to invoke a method in a backing bean when you click on an item in the View, you'll need to set up an AJAX event in the View Definition. Or alternatively, expect it to refresh the entire page.

JSPs are not used in JSF version 2, incidentally. The View Template Language/View Definition Language for JSF2 is the facelets xhtml.
 
Don't get me started about those stupid light bulbs.
 
subject: Displaying a value in <h:outputText> when some event occurs
 
Similar Threads
Header, Footer with dynamic data
disabled issue for inputtext
RichFaces 3.3.3 - rich:datascroller doesn't refresh
richfaces:: richdatatable problem.
Rich:Datatable rerendering problem