I'm not sure "event" is the best name for your input. You might consider
changing it to <s:select name="currentProject"> or something.

Stripes will select the correct option based on the value of either a
request attribute named currentProject, if there is one, or the property
named currentProject in your SwitchProjectActionBean. But it will only do
the latter if there is an instance of SwitchProjectActionBean in your
request. I don't often suggest using s:useActionBean, but in this case it's
the simplest way to go. So you'll instantiate your SwitchProjectActionBean
using s:useActionBean, make sure its getCurrentProject() method always
returns the current project, and Stripes will select the option based on
that.

-- In your JSP
<s:useActionBean var="switchProjectActionBean"
    beanclass="blah.action.SwitchEventActionBean" />
<s:form beanclass="blah.action.SwitchEventActionBean">
 <s:select name="currentProject">
   <s:options-collection
      collection="${switchProjectActionBean.currentUser.projects}"
      label="name" />
 </s:select>
 <s:submit name="switch" value="switch" />
</s:form>

-- In your SwitchProjectActionBean

public Project getCurrentProject() {
  return getCurrentUser().getCurrentProject(); // or however you do it
}

That should do the trick. No promises, though :)

-Ben

PS: It's worth noting that if you do, indeed, get and set the current
project using User.getCurrentProject() and User.setCurrentProject() then you
can name your s:select currentUser.currentProject and just have a
getter/setter for currentUser on your ActionBean.

On Sat, Feb 14, 2009 at 10:54 AM, Eric Palmitesta <[email protected]>wrote:

> Typo, SwitchEventActionBean should have been SwitchProjectActionBean.
>
> Levi, I'm new to stripes, I'm not sure what that means.  The current
> ActionBean isn't SwitchProjectActionBean.  SwitchProjectActionBean is
> just an ActionBean I bounce off of to perform the switching logic and
> redirect to another ActionBean, it has no view logic.
>
> Eric
>
> Also, SwitchProjectActionBean
>
> On Sat, Feb 14, 2009 at 10:35 AM, Levi Hoogenberg
> <[email protected]> wrote:
> > You have to make sure that your event getter (on SwitchEventActionBean)
> > returns the current project. You can do this in a before method (a method
> > that's marked with @Before) or in a pre-action, if you have any.
> >
> > Regards,
> >   Levi
> >
> > On Sat, Feb 14, 2009 at 4:16 PM, Eric Palmitesta <[email protected]>
> > wrote:
> >>
> >> Users have Projects, and can view one at a time.
> >>
> >> class User {  Set<Project> projects; Project current; }
> >> class Project { String name; }
> >>
> >>  My BaseActionBean has methods to retrieve the currently logged in
> >> User, and the Project they're currently viewing:
> >>
> >> User getCurrentUser() { ... }
> >> Project getCurrentProject() { ... }
> >>
> >> I want a select box which lists all the Projects the currently logged
> >> in User has, with a Swtich button which submits to a
> >> SwitchEventActionBean, which does the work of switching to the newly
> >> selected event.
> >>
> >> <s:form beanclass="blah.action.SwitchEventActionBean">
> >>  <s:select name="event">
> >>    <s:options-collection
> >> collection="${actionBean.currentUser.projects}" label="name" />
> >>  </s:select>
> >>  <s:submit name="switch" value="switch" />
> >> </s:form>
> >>
> >> This does everything properly, thanks to stripersist.  That's the
> >> setup for my question.
> >>
> >> How do I pre-select the Project a User is currently viewing in that
> >> select box?  No javascript.
> >>
> >> Putting a selected="true" attribute in the options-collection tag
> >> yields "Attribute selected invalid for tag options-collection
> >> according to TLD", even though the tag lib docs say "All other
> >> attributes on the tag (other than collection, value, label and group)
> >> are passed directly directly through to the stripes:option tag which
> >> is used to generate the individual HTML options tags", so that's
> >> unexpected.
> >>
> >> Suggestions?
> >>
> >> Cheers,
> >>
> >> Eric
> >>
>
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to