-
1. Re: How can I pass parameters to action methods
christian.bauer Mar 6, 2007 1:46 PM (in response to javarebel)You need to understand the JSF request lifecycle. In the request in which your page is rendered, page.globalListingsId can be successfully resolved in some context. Apparently it can't be resolved in any context (session, conversation, event, etc.) when you do the next request and execute the action. The callThisAction(parameter) syntax in the EL is really just a shortcut for a lookup/injection of that "parameter" contextual variable that happens when the action is executed.
-
2. Re: How can I pass parameters to action methods
javarebel Mar 6, 2007 4:33 PM (in response to javarebel)My requirement is to get an identifier in which link I have clicked in the backing bean. I am able to find a solution for this.
In XHTML File
-------------------------
<c:forEach items="#{listingSearch.pagesLinks}" var="page">
<s:link action="#{listingSearch.next()}"
value="#{page.globalListingId}">
<f:param name="linkId" value="#{page.globalListingId}" />
</s:link>
</c:forEach>
In Backing bean
-----------------------
@RequestParameter
private String linkId;
public void next() {
System.out.println("You Clicked on link Id : " + this.linkId);
return;
}
or
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)
facesContext.getExternalContext().getRequest();
String linkIdFromCtx = ((String[])request.getParameterMap()
.get("linkId"))[0];
System.out.println("Ctx: You Clicked on link Id : " + linkIdFromCtx); -
3. Re: How can I pass parameters to action methods
christian.bauer Mar 6, 2007 4:52 PM (in response to javarebel)You need to look at the Seam example applications, or really, any JSF example application. I often had the same reflex when I started learning JSF and tried the same approach as you. You can not pass "objects" between requests by putting them into a link.
Check the booking demo app and how it uses @DataModel and @DataModelSelection, this is what you probably want. -
4. Re: How can I pass parameters to action methods
javarebel Mar 6, 2007 5:08 PM (in response to javarebel)I can't use DataModel and DataModelSelection because I can't use DataTable. I need to render the links horizontally. Is there anyway I can render DataTable horizontally?
-
5. Re: How can I pass parameters to action methods
christian.bauer Mar 6, 2007 5:33 PM (in response to javarebel)So you need to find another way to pass an "object" from request to request. One way is to pass its identifier and to load it from the database in the second request. Another is to stick it into the session an retrieve it from there by identifier.
And the last and best way is to put it into the conversation context in the first request, name the context variable in the action method as a parameter, and let Seam look it up from the conversation context in the second request. This is really what Seam is about. -
6. Re: How can I pass parameters to action methods
christian.bauer Mar 6, 2007 6:42 PM (in response to javarebel)Btw, don't use JSTL with JSF, it's a bad combination. You are already using Facelets, so add xmlns:ui="http://java.sun.com/jsf/facelets"
and work with <ui:repeat> instead. -
7. Re: How can I pass parameters to action methods
spambob Mar 6, 2007 7:14 PM (in response to javarebel)Sorry to jump in here but I actually had the same problem!
"christian.bauer@jboss.com" wrote:
...And the last and best way is to put it into the conversation context in the first request, name the context variable in the action method as a parameter, and let Seam look it up from the conversation context in the second request. This is really what Seam is about.
As far as I understood it he has a list as a context variable and wants to pass the id of an object contained in the list as action method parameter.
So the list is within conversation context but JSF doesn't resolve the id to some string that is therefore null but it would work if he would write "listingSearch.next(3) - in case page.globalListingId would be 3.
So is there any way to force JSF to resolve "page.globalListingId" to a string (assuming it is an Integer, String, ... - anything that can be cast to string without problems)?
I would greatly appreciate any hints / 2 line examples because this has been some pain for me too.
Thanks a lot in advance! -
8. Re: How can I pass parameters to action methods
christian.bauer Mar 6, 2007 7:31 PM (in response to javarebel)No, JSF is dumb. You could create a Facelets function and call it like this: #{myFunctions:myToString(o)}
-
9. Re: How can I pass parameters to action methods
spambob Mar 6, 2007 7:35 PM (in response to javarebel)Ahh, I see.
Thank you very much! -
10. Re: How can I pass parameters to action methods
monkeyden Mar 9, 2007 10:55 AM (in response to javarebel)Can you define variable argument EL functions in tld files, as in:
<function-signature> java.lang.String concat(java.lang.String...) </function-signature>
public static String concat(String... strings) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < strings.length; j++) sb.append(strings[j]); return sb.toString(); }
-
11. Re: How can I pass parameters to action methods
gavin.king Mar 9, 2007 7:33 PM (in response to javarebel)No, its not supported by EL.
-
12. Re: How can I pass parameters to action methods
cupdike Sep 26, 2007 10:07 AM (in response to javarebel)"christian.bauer@jboss.com" wrote:
So you need to find another way to pass an "object" from request to request. One way is to pass its identifier and to load it from the database in the second request. Another is to stick it into the session an retrieve it from there by identifier.
But the booking app does pass the object as a parameter [from main.xhtml]:<h:dataTable id="hotels" value="#{hotels}" var="hot" rendered="#{hotels.rowCount>0}"> ... <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>
The only reason I can guess why this works is that the hotels DataModel property is outjected from a session-scoped SFSB. However, I read in one of Dan Allen's articles on IBM thatOutjected variables are placed directly into the variable context, independent of their backing bean.
So this suggests that it shouldn't matter.
Continuing..."christian.bauer@jboss.com" wrote:
And the last and best way is to put it into the conversation context in the first request, name the context variable in the action method as a parameter, and let Seam look it up from the conversation context in the second request. This is really what Seam is about.
Doesn't it depend on what the bounds of the conversation are? According to the Yuan/Heute book,The default conversation scope spans only two pages
However, I find this statement a bit misleading. If you read further, it suggests that is really a single request/response cycle. And wouldn't this then explain why trying to pass the object using default conversation scope doesn't work? But then how does it work in the booking app, unless the scope of the component outjecting the property has some influence on the lifecycle of the outjected property.
Clearly I'm missing something I need to know about how all this works. Please someone explain.
TIA, Clark -
13. Re: How can I pass parameters to action methods
cupdike Sep 26, 2007 10:15 AM (in response to javarebel)Apologies to Yuan/Heute, there's really nothing misleading about their statement. They spelled it out pretty clearly when I reread section 7.1.
-
14. Re: How can I pass parameters to action methods
christian.bauer Sep 26, 2007 10:33 AM (in response to javarebel)But the booking app does pass the object as a parameter [from main.xhtml]:
No, it's magic.
http://jira.jboss.com/jira/browse/JBSEAM-1734