I did try the following way:

1) I have the following lines under applicationContext-struts.xml

<bean id="userAction" class="org.appfuse.webapp.action.UserAction"
scope="prototype">
        <property name="userManager" ref="userManager"/>
        <property name="roleManager" ref="roleManager"/>
        <property name="clubManager" ref="clubManager"/>
        <property name="mailEngine" ref="mailEngine"/>
        <property name="mailMessage" ref="mailMessage"/>        
        <property name="templateName" value="accountCreated.vm"/>
 </bean>

2) In my UserAction.java's edit method, I have this

clubs = clubManager.getClubs();     

3) In my userForm.jsp, I have

<s:select label="%{getText('user.club')}"
     name="user.club.clubID"
     value="user.club.clubID" listValue="clubName" listKey="clubID"
     list="clubs" /> 

It works, except it seems like there is a JPA persistence issue in my user
pojo & club pojo.

Will update the progress once I get it done. Thanks


dusty wrote:
> 
> In your previous post it looked like you had some trouble with the ClubDao
> wiring.  You call the constructor explicitly but I think you want Spring
> to inject the dao so it comes injected with its dependant SessionFactory. 
> It looks like the ClubDao you create has no SessionFactory or is not wired
> up so the underlying HibernateTemplate is not working.
> 
> In your UserAction, try to throw in a debugging log message like
> log.debug(clubs.size()) after you get the club list from your ClubManager. 
> I suspect that it is coming back as 0.  This means you may have a Spring
> configuration issue with your ClubManager and ClubDao.  Please post your
> applicationContext file for your dao, service and web actions.
> 
> The actual JSP tag looks right and there doesn't seem to be anything wrong
> with your Club model object.
> 
> -D
> 
> 
> Fan wrote:
>> 
>> I put the following line in my userForm, but it just did not show on the
>> screen. It did not even have any error message
>> 
>> 
>> <ww:select list="clubs" listKey="clubID" listValue="clubName"
>> name="user.club.clubID"/>
>> 
>> in my UserAction.java's edit method, I do have
>> 
>> clubs = clubManager.getClubs();
>> 
>> then I did make a getter in UserAction.java too
>> 
>> public List getClubs(){
>>      return clubs;
>> }
>> 
>> In my User.java,I do have 
>> 
>> protected Club club = new Club();
>> 
>>     ManyToOne
>>     @JoinColumn(name="clubID")
>>     public Club getClub()
>>     {
>>      return club;
>>     }   
>> 
>> 
>> here is my Club.java getter methods for the clubID and clubName
>> 
>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>      public Long getClubID() {
>>              return clubID;
>>      }
>> 
>> 
>> @Column(nullable=false, length=50)
>>      public String getClubName() {
>>              return clubName;
>>      }
>> 
>> 
>> From the above codings, what did I miss out ? 
>> 
>> p/s ** I am using 2.0-M5 struts basic
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> dusty wrote:
>>> 
>>> It depends on how you want to implement this.  Presumably you want to
>>> assign a user to a single club (ManyToOne).  If a user could be in many
>>> clubs then it would be a ManyToMany.  But lets stick with ManyToOne
>>> and/or the inverse side Club to User OneToMany.
>>> 
>>> In appfuse2 you are insulated from the infrastructure code such as the
>>> UserAction and userForm.jsp.  So to change what information is available
>>> to the standard form you would would need to change the source of
>>> UserAction and then update your form with your drop-down.  This means
>>> you will need to use the appfuse:install-full-source (or something like
>>> that) so you can modify the source code.  People have had similar issues
>>> when they have wanted to extend the User object to include additional
>>> properites needed in their application.  I am assuming that you have not
>>> yet modified the User object to include:
>>> 
>>> @ManyToOne
>>> private Club club;
>>> 
>>> Before I give you an alternate solution lets go down the modifying
>>> Appfuse infrastructure road, knowing that it causes issues about
>>> upgrading to future versions of that Appfuse code.  Lets pretend you
>>> don't care about that.  So you need the following:
>>> 
>>> User.java
>>> - The annotation  I mentioned above.
>>> - The club getter and setter on the User object
>>> 
>>> UserAction.java
>>> private List clubs;
>>> clubs = dao.getObjects(Club.class);
>>> getter for clubs;
>>> 
>>> All this assumes you have clubs in the db and can create and delete
>>> those clubs as you need to.   At this point you have enough to populate
>>> your drop-down box with your clubs List.
>>> 
>>> <ww:select list="clubs" listKey="[club id fieldname]" listValue="[club
>>> name field name]" name="user.club"/>
>>> 
>>> Here is the tricky part.  When you select a value from your club
>>> drop-down the value you post is going to be just a number, the id of the
>>> club selected (see listKey = id).  How does Struts know how to make this
>>> number a reference to a full-blown Club object.  The short answer is
>>> that it doesn't.   Struts has no built-in type converter to take the
>>> string "1" and turn it into a Club.  So the fancy way to tell struts how
>>> to convert the 1 to a club is to use custom type conversion.  Frankly,
>>> its still a bit of a mystery to me but I have been able to make it work
>>> by using examples in the documentation.  The poor mans way to do this is
>>> to include the following in your save method:
>>> 
>>> Long clubIdL = Long.parseLong(clubId);
>>> Club club = (Club)dao.getObject(Club.class,idL);  //I always use Longs
>>> for my id so that is the reason for the cast.  I have no idea what type
>>> your ids are.
>>> user.setClub(club);
>>> dao.saveObject(user);
>>> 
>>> The rest of the normal (non-relationship text values) will be converted
>>> by struts and so you don't have to worry about setting those.  
>>> 
>>> If you care about backwards or forwards Appfuse compatability then:
>>> You have a few options and they depend on your requirements.  The
>>> easiest route is to keep the relationship on the Club side (@OneToMany),
>>> but that means you have to look at the club to see what users are in the
>>> club.  You won't be able directly do something like user.getClub(). 
>>> Then you would create a separate page for assigning users to clubs.  It
>>> would be a custom Action and jsp page you write yourself.  
>>> 
>>> The other option is to encapsulate the Appfuse User object in your own
>>> super object.  Its not inheritance buy composition so that the Appfuse
>>> User is a property of your new object.  (public User myuser.getUser();)  
>>> 
>>> So you can see there are many options, and it depends on what you need
>>> and what you are comfortable implementing on your own.  As usual I
>>> rambled too much, but I hope it helps.... ;-)
>>> 
>>> -D
>>> 
>>> 
>>> 
>>> Fan wrote:
>>>> 
>>>> I am using struts framework in Appfuse 2.0-m5. 
>>>> 
>>>> I have a POJO called Club, now I want to retrieve the list of clubs
>>>> from DB then populate them into userForm.jsp as a combo box. How could
>>>> I do that ? Any pointer please
>>>> 
>>>> p/s ** The relationship between User and Club POJO is ManyToOne.
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/struts-combo-box-tf3997691s2369.html#a11432998
Sent from the AppFuse - User mailing list archive at Nabble.com.

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

Reply via email to