5274

Rendering a div with ajax

Question:

I have this div

<div id="name"> .... </div>

I also have a button that does this:

<h:commandLink id="bttn" action="#"> <f:ajax render="name"/> </h:commandLink>

The problem is that when executing, it says that there is no component called "name". Is there a way I can render a div with an ajax <strong>without enclosing it within a jsf component</strong>?

Answer1:

No, there's no way. Ajax rendering works roughly as follows under JSF's hoods:

for (String clientIdToRender : clientIdsToRender) { UIComponent componentToRender = viewRoot.findComponent(clientIdToRender); // ... }

However, as the plain HTML <div> is <em>not</em> as a fullworthy JSF component available by <a href="http://docs.oracle.com/javaee/6/api/javax/faces/component/UIComponentBase.html#findComponent%28java.lang.String%29" rel="nofollow">UIViewRoot#findComponent()</a>, JSF can't find anything to generate the updated HTML output for.

You do not necessarily need to wrap it in another JSF component, you can also just use a JSF component which generates already a HTML <div> element. That is the <h:panelGroup> component whose layout attribute is set to block (as in, "render a <a href="https://developer.mozilla.org/en-US/docs/HTML/Block-level_elements" rel="nofollow">block level</a> element").

<h:panelGroup layout="block" id="name"> ... </h:panelGroup> <h3>See also:</h3> <ul><li><a href="https://stackoverflow.com/questions/13009174/jsf-update-with-ajax-non-jsf-things/" rel="nofollow">Is it possible to update non-JSF components (plain HTML) with JSF ajax?</a></li> </ul>

Recommend

  • Difference between calling new and getInstance()
  • how to debug an internal error?
  • Javadoc generation for Android
  • Difference between enum and enum class [duplicate]
  • TagException … null (File not found) on creating custom Facelets tag [duplicate]
  • How would I call a JavaScript function from a JSF Bean?
  • Drag and Drop between different layout units in Primefaces
  • javafx 3d performance large data set
  • Scala split a multi line string by lines that contain all hyphens
  • JSF2.0 + Primefaces 3.0.1 + jquery 1.6.4 + p:commandLink + IE8 throws Unexpected call to method or p
  • Rails 5 - Google Maps - Javascript error - initMap is not a function - fixing one js issue creates a
  • Google OAuth: can't get refresh token with authorization code
  • How to render a pixel array most efficiently to a window in c++?
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • Adjust width of select element according to selected option's width
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Moving mysql files across servers
  • $wpdb not working in file of WordPress plugin
  • Django rest serializer Breaks when data exists
  • Typescript - Unable to get 'import' statement to function
  • How to use an array of arrays with array_map(…) in PHP?
  • Paperclip, set path outside of rails root folder
  • R - Combining Columns to String Based on Logical Match
  • Get one-time binding to work for ng-if
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • Display issues when we change from one jquery mobile page to another in firefox
  • Updating server-side rendering client-side
  • Running a C# exe file
  • Do create extension work in single-user mode in postgres?
  • Why winpcap requires both .lib and .dll to run?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • How to set the response of a form post action to a iframe source?
  • apache spark aggregate function using min value
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android
  • Sorting a 2D array using the second column C++
  • How to load view controller without button in storyboard?