• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF AJAX issue with ui:repeat

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am facing refresh issue when I call AJAX from a commandLink in side ui:repeat. It works fine when it is from outside.


When I click on remove commandLink, it triggers action class method and removes from the member list but in UI it is showing the same. AJAX call response is here:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="j_id1:javax.faces.ViewState:0"><![CDATA[-1008898607242478710:-5583286680371853580]]></update></changes></partial-response>

This works when I use JSTL foreach. When I inspected, the ID of command link is form:j_idt802:5:j_idt769:0:removeLink when it is inside ui:repeat. When it is in forEach or outside ui:repeat, it's form:removeLink and it works.

Any please suggest a clear solution for this.

Thanks,

Valsaraj Viswanathan
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Valsaraj!

We have a special button on our message editor that adds "code" tags. Code tags can be use to wrap pre-formatted text such as Java code or XML and make those items easier to read. I've applied a set of code tags to your sample.

When defining a View template where data is in 2-dimensional row/column format, it's much simpler to use the h:dataTable tag instead of using brute-force HTML and a looping construct (ui:repeat). Also, the dataTable pairs with a DataModel value object that will wrap your data collection with extra functions that keep you from having to code parameters on the View. Anything logic-like on a View Template is generally not a good idea.

Also, whenever you see an element ID in the form "j_1234", that means that the corresponding template element did not have an explicit ID, so the JSF html/xml renderer synthesized one. JSF uses a concept called "naming containers" to ensure that JSF-generated HTML elements will all have unique ids (which is required to be XML-compatible).
 
valsaraj viswanathan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

We used dataTable first and removed because it works as expected with DataModel type object only. The object what we get in view is a list object.

I have set ID to form and commandLink but the j_1234 part was due to ui:repeat. How can we avoid this? It's coming for all components inside ui:repeat even if we set id to those components.

I found reason for why view is not updated. When it is in forEach or outside ui:repeat, <f:ajax execute="schedulesContainer" render="schedulesContainer" /> will work fine because they are under a form with id "form" and by default the element schedulesContainer will be found in view which has id form:schedulesContainer. But when it is used inside ui:repeat, <f:ajax execute="schedulesContainer" render="schedulesContainer" /> call won't be able to find a component with client id schedulesContainer under that view form:j_idt802:5:j_idt769 where link has id form:j_idt802:5:j_idt769:0:removeLink. That's why AJAX repsonse is view state instead of partial view. This is resolved by specifying actual id of component, ie form:schedulesContainer. Eg: <f:ajax execute="schedulesContainer" render="form:schedulesContainer" />.

 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not understand. If you have a List and want to use it as a UI model object, wrap it in a ListDataModel and use the dataTable.
 
valsaraj viswanathan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I have a nested data structure which is generated from xml. So list is only a part of bean.data member value. So using wrapper to convert list to DataModel adds additional work and more changes. That is the reason why ui:repeat is used. dataTable is limited to server row index for DataModel items only.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't matter WHERE the list came from. As long as it implements java.util.List, you can wrap it in a ListDataModel using a single statement with no changes at all to the list itself. That's what DataModels are for, to allow POJO model objects to be decorated with JSF-enhancing functionality.

If it's not a java.util.List, that's fine. There's also a DataModel for arrays. Any ordered data collection can be wrapped in some kind of DataModel.

And if the data isn't ordered, then you have bigger problems which ui:repeat cannot handle either, since the multi-pass nature of the JSF UI demands that the data row fetch process be idempotent. If data comes in in a different sequence, it wrecks the rendering process.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic