[jboss-user] [JBoss Seam] - @DataModel s:link h:commandButton h:dataTable

djfjboss do-not-reply at jboss.com
Thu Dec 6 12:03:08 EST 2007


I'm very puzzled regarding the behaviour and interaction of the above components.  I have used them successfully in some contexts, but am having problems with them in other contexts but can't see any pattern.

My understanding was that s:link is to be preferred over the non-Seam h:commandButton but things do not seem to be quite that simple as this simple example demonstrates:


  | <rich:panel>
  | 			<f:facet name="header">Why Doesn't This Work?</f:facet>
  | 			<h:form>
  | 				<h:dataTable value="#{accountService.things}" var="thing">
  | 					<h:column>
  | 						<f:facet name="header">Name</f:facet>
  | 						<h:outputText id="name" size="10" required="true"
  | 							value="#{thing.name}">
  | 						</h:outputText>
  | 					</h:column>
  | 					<h:column>
  | 						<f:facet name="header">Size</f:facet>
  | 						<h:outputText id="size" size="10" required="true"
  | 							value="#{thing.size}">
  | 						</h:outputText>
  | 					</h:column>
  | 					<h:column>
  | 						<s:link value="Select"
  | 							action="#{accountService.selectThing(thing)}" />
  | 					</h:column>
  | 					<h:column>
  | 						<h:commandButton value="Select"
  | 							action="#{accountService.selectThing(thing)}" />
  | 					</h:column>
  | 					<h:column>
  | 						<s:link value="Select (dsm)"
  | 							action="#{accountService.selectThing()}" />
  | 					</h:column>
  | 					<h:column>
  | 						<h:commandButton value="Select (dsm)"
  | 							action="#{accountService.selectThing()}" />
  | 					</h:column>
  | 				</h:dataTable>
  | 
  | 				<h:commandButton value="Show Choices"
  | 					action="#{accountService.getThings()}" />
  | 			</h:form>
  | 		</rich:panel>
  | 


and the corresponding service class:


  | 	@DataModel
  | 	private List<Thing> things;
  | 
  | 	@DataModelSelection("things")
  | 	private Thing selectedThing;
  | 
  | 	public List<Thing> getThings() {
  | 		ThingRepository repository = new ThingRepository();
  | 		things = repository.getThings();
  | 		return things;
  | 	}
  | 
  | 	public String selectThing() {
  | 		log.info("### DJF Selected: " + selectedThing);
  | 		return null;
  | 	}
  | 
  | 	public String selectThing(Thing thing) {
  | 		selectedThing = thing;
  | 		log.info("### DJF Selected: " + selectedThing);
  | 		return null;
  | 	}
  | 

(yes I know I should use a static for the repository ...)

The repository spits out:
  One_1
  Two_22
  Three_333
  Four_4444
  Five_55555
  Size_666666

I then select the second, third, fourth and fifth lines (in that order) with the following surprising (to me at least) results:

16:54:43,322 INFO  [AccountService] ### DJF Selected: null
16:54:44,665 INFO  [AccountService] ### DJF Selected: Three_333
16:54:45,931 INFO  [AccountService] ### DJF Selected: One_1
16:54:47,353 INFO  [AccountService] ### DJF Selected: One_1

One out of four is correct!  Why null?  Why does it incorrectly select the first element when I have selected a different element?


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4110928#4110928

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4110928



More information about the jboss-user mailing list