-
1. Re: Iteration and s:link
dhinojosa Aug 10, 2008 11:31 PM (in response to gzoller.greg.zoller.aviall.com)Can we see what cart manager and cart look like?
-
2. Re: Iteration and s:link
gzoller.greg.zoller.aviall.com Aug 11, 2008 3:06 AM (in response to gzoller.greg.zoller.aviall.com)Here's a version of this behavior in two files. The actual code is huge, so I can recreate this behavior in small form here--compressed app logic into the manager class.
XHTML:
<h:form> <rich:panel header="Emails"> EMAILS: <a4j:outputPanel id="wow"> <a4j:repeat id="rep" value="#{mgr.emails}" var="email"> <s:link value="#{email}" action="#{mgr.edit(email)}" /><br/> </a4j:repeat> </a4j:outputPanel> <br/> <rich:inplaceInput defaultLabel="(add more)" selectOnEdit="true" value="#{mgr.scratch}"> <a4j:support event="onviewactivated" action="#{mgr.addEmail()}" reRender="wow" /> </rich:inplaceInput> </rich:panel> </h:form>
Manager Class:
@Name("mgr") @Stateful @Scope(ScopeType.SESSION) public class ManagerBean implements Manager { private HtmlInplaceInput emailRef; private UIRepeat repeater; private List<String> emails = new ArrayList<String>(); private String scratch="Hey"; private Set<Integer> keys = null; public Set<Integer> getKeys() { return keys; } public void setKeys(Set<Integer> keys) { this.keys = keys; } public List<String> getEmails() { return emails; } public void addEmail() { System.out.println("ADD!" +scratch); emails.add(new String(scratch)); scratch = null; } public String getScratch() { return scratch; } public void setScratch(String scratch) { this.scratch = scratch; } public void edit(String index) { System.out.println("EDIT INDEX: " + index); } @Remove @Destroy public void destroy() {} }
The add/display part is working but when I click on the links inside my repeat clause nothing is passed to mgr.edit(). How can I pass in the one selected?
Ultimately I will make these edit fields, not links so the user can edit addresses in the list. For now I'll rig the s:link to simply delete the selected address from the list.
I saw some complex examples using binding but then read something in the Seam docs that suggested binding wasn't desirable--didn't work with conversations or something. Don't really understand all the nuances of binding and the examples I tried to emulate died w/exceptions (i.e. binding the a4j:repeat to a UIRepeat object, etc.). Is that what I'm going to need here to get the desired behavior?
Thanks for any advise.
Greg -
3. Re: Iteration and s:link
dhinojosa Aug 11, 2008 4:53 AM (in response to gzoller.greg.zoller.aviall.com)Oh, yeah! We had this a few days ago...try putting a @DataModel annotation on the email list.
-
4. Re: Iteration and s:link
cash1981 Aug 11, 2008 3:54 PM (in response to gzoller.greg.zoller.aviall.com)Try to do like this:
You create your s:link with f:param
<s:link view="/MyHome.xhtml" value="Choose" action="#{someManager.choose}"> <f:param name="organisationId" value="#{org.organisationId}"/> </s:link>
And then in your stateful bean:
@RequestParameter private String organisationId;
This will then be injected and you can get it from your action.
Hope this helps
-
5. Re: Iteration and s:link
gzoller.greg.zoller.aviall.com Aug 11, 2008 4:37 PM (in response to gzoller.greg.zoller.aviall.com)Tried this approach and came up getting null value for the parameter.
<s:link style="padding-left:3px;" value="#{email}" action="#{cartMgr.cart.selectEmail}"> <f:param name="emailId" value="#{email.id}"/> </s:link>
Then in my Java code for cart
@RequestParameter private Integer emailId; ... public void selectEmail() { System.out.println("SELECTED EMAIL: " + emailId); }
In my EmailAddress object (email's type) I have a trivial id generator:
private static int idCount = 0; private Integer id = new Integer(idCount++); public Integer getId() { return id; }
When run my output statement comes back w/NULL. Any ideas why? ALso tried String data type for id but that didn't matter. I'll also try the DataModel approach Daniel suggested.
Thanks,
Greg -
6. Re: Iteration and s:link
gzoller.greg.zoller.aviall.com Aug 11, 2008 4:45 PM (in response to gzoller.greg.zoller.aviall.com)Hang on, ya'll. My bad. The @RequestParameter is working. I was trying to inject it into an object that wasn't a Seam component. D'oh! Fixed that up and we're working great.
Thanks a million for the help and I'll also keep the DataModel approach in mind as well as that may be a good way to handle another issue I'm working.
Greg