How to use multi select or checkboxlist in Struts 2

2007-10-21 Thread Stephen de Vries


Hi,

I'm having a problem using a checkboxlist to update a list in my  
model and can't find any example of using checkboxlist on the web.   
Displaying the checkboxes works fine, but not saving their values to  
the model.  And I'm not exactly clear on how the checkboxlist does  
the conversion from string to my defined type.  Project uses spring  
2, hibernate and JPA:


@Entity
public class Recipient {
private Long id;
private ListProfile profiles = new ArrayListProfile();

public ListProfile getProfiles() {
return profiles;
}
...
@Entity
public class Profile {
private Long id;
private String name;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}

...

public class RecipientAction extends BaseAction implements Preparable {
private ListProfile allProfiles;
private Recipient recipient;
private Long  id;

public String save() throws Exception {
boolean isNew = (recipient.getId() == null);
recipientManager.save(recipient);

String key = (isNew) ? recipient.added : recipient.updated;
saveMessage(getText(key));

if (!isNew) {
return INPUT;
} else {
return SUCCESS;
}
}
...

recipientForm.jsp:

s:checkboxlist list=allProfiles listKey=id listValue=name  
label=Profiles  name=recipient.profiles/


When executing recipientManager.save(recipient); the application  
throws the exception:


org.hibernate.PropertyAccessException: IllegalArgumentException  
occurred calling getter of com.corsaire.contactn.model.Profile.id

...
Caused by: java.lang.IllegalArgumentException: object is not an  
instance of declaring class


Any ideas as to what's wrong?  Do I need to provide an explicit  
conversion from Strings to ListProfile?


regards,
Stephen



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [S2] Access a SiteMesh Object in a Struts tag

2007-10-21 Thread Grish

After going through the OGNL documents and trial and error I was able to get
the properties from the page object from sitemesh using the following code:

decorator:usePage id=myPage /
s:set name=currentNav
value=%{#attr.myPage.getProperty('meta.currentNav')} /

Hope this is of some use to someone out there :)


Grish wrote:
 
 So I tried the following:
 
 decorator:usePage id=myPage /
 % String current = myPage.getProperty(meta.current); %
 s:set name=currentPage value=#attr.current /
 !-- s:property value=#currentPage / --
 
 but this displays blank. What I want to do is get the property from the
 Page object of sitemesh and make it accessible to my s2 tags. I was
 reading about OGNL and the syntax but i can't seem to get that property.
 Is my syntax incorrect?
 
 
 Grish wrote:
 
 Hi,
 
 I was wondering if this is possible, I want to access a SiteMesh object
 in a struts tag like the set tag:
 
 I want to access the Page object from SiteMesh and get a property from
 that object and assign it a value
 
 decorator:usePage id=myPage /
 
 s:set name=currentPage value= /
 
 where value would be myPage.getProperty(meta.curentPage).
 
 I have a feeling i'm just using incorrect syntax. Can anyone point me to
 the right direction?
 
 Thanks!
 
 
 

-- 
View this message in context: 
http://www.nabble.com/-S2--Access-a-SiteMesh-Object-in-a-Struts-tag-tf4646229.html#a13336246
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]