(struts/JSTL) Setting bean property value with jstl choose compoundresults

Discussion in 'Java' started by DaFoot, Oct 23, 2008.

  1. DaFoot

    DaFoot Guest

    Probably not a very good subject, but best I could come up with!

    I have some JSTL in a (struts backed) JSP that creates a statement on
    the page like this:

    Code:
    Some text
    	${registrationForm.map.CLI} more text
    	<c:choose>
    		<c:when test="${registrationForm.map.responseCode eq 'Lin-2a'}">
    				at least ${registrationForm.map.displayableMax}.
    		</c:when>
    		<c:when test="${registrationForm.map.responseCode eq 'Lin-2b'}">
    				between ${registrationForm.map.displayableMax} and 8.
    		</c:when>
    		<c:otherwise>
    				up to ${registrationForm.map.displayableMax}.
    		</c:otherwise>
    	</c:choose>
    
    So I would get something like this in the page:
    Some text <form.CLI.value> more text [at least<var>|between<var> and 8|
    up to <var>]

    I need to find a way to save that entire output string to another
    action form property. Simple assignments should be an issue, but I
    have no idea how to concat strings into a property using JSTL
    (alternatively could use a java scriptlet in the page, but trying to
    move away from that approach).

    Any suggestions gratefully received.
    DaFoot, Oct 23, 2008
    #1
    1. Advertising

  2. DaFoot

    DaFoot Guest

    Re: (struts/JSTL) Setting bean property value with jstl choosecompound results

    On Oct 23, 1:05 pm, Lew <> wrote:
    > DaFoot wrote:
    > > Probably not a very good subject, but best I could come up with!

    >
    > > I have some JSTL in a (struts backed) JSP that creates a statement on
    > > the page like this:

    >
    > >
    Code:
    > > Some text
    > >    ${registrationForm.map.CLI} more text
    > >    <c:choose>
    > >            <c:when test="${registrationForm.map.responseCode eq 'Lin-2a'}">
    > >                            at least ${registrationForm.map.displayableMax}.
    > >            </c:when>
    > >            <c:when test="${registrationForm.map.responseCode eq 'Lin-2b'}">
    > >                            between ${registrationForm.map.displayableMax} and 8.
    > >            </c:when>
    > >            <c:otherwise>
    > >                            up to ${registrationForm.map.displayableMax}.
    > >            </c:otherwise>
    > >    </c:choose>
    > > 

    >
    > > So I would get something like this in the page:
    > > Some text <form.CLI.value> more text [at least<var>|between<var> and 8|
    > > up to <var>]

    >
    > > I need to find a way to save that entire output string to another
    > > action form property. Simple assignments should be an issue, but I
    > > have no idea how to concat strings into a property using JSTL
    > > (alternatively could use a java scriptlet in the page, but trying to
    > > move away from that approach).

    >
    > Sounds like you are mixing view and logic.  Action forms are supposed to be
    > about communication of the dynamic data that flows between the user and the
    > model.  Details of layout and prompt should be the exclusive province of the JSP.
    >
    > That said, sometimes you have to break the rules, for expediency or other
    > purpose, and you are willing to pay the technical debt for it.
    >
    > Keep the entire prompt in the form in the first place, and compute the various
    > pieces server side.  The same logic that computes
    > registrationForm.map.displayableMax could also compute the entire string.
    >
    > --
    > Lew


    Quite right Lew, that is how it *should* be done ;)

    Would be awkward to do that because of the flows through the
    application. Right now I'm thinking creating a <html:hidden ... >
    element inside each choose is the way forward, but environment issues
    slowing me down in testing stuff!
    DaFoot, Oct 23, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas P. Fuller
    Replies:
    1
    Views:
    4,514
    bitbucket43
    Aug 17, 2004
  2. Bob Rivers
    Replies:
    1
    Views:
    5,918
    Tobias Schierge
    Feb 3, 2005
  3. jill
    Replies:
    5
    Views:
    15,538
  4. Richie
    Replies:
    6
    Views:
    458
    Richie
    Mar 28, 2008
  5. Replies:
    3
    Views:
    2,473
    Donkey Hot
    Apr 10, 2008
Loading...

Share This Page