Haven't tried this yet, but it's a bit more concise and should be equivalent:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"; %>

<jsp:useBean id="configHelper"
             class="org.apache.struts.config.ConfigHelper"/>
<c:set target="${configHelper}"
       property="request"
       value="${pageContext.request}"/>
<c:set var="form" value="${configHelper.actionForm}"/>

Brandon Goodin wrote:
yes,

you can use jstl to locate your form. then you can access it's properties
via el and use the jstl tags for display.

Here is the jsp code to accomplish this

---- code start ----
<[EMAIL PROTECTED] prefix="c" uri="/WEB-INF/tld/c.tld" %>

<c:set
        var="formName"
        value="${requestScope['org.apache.struts.action.mapping.instance'].name}"/>

<c:set
        var="formScope"
        value="${requestScope['org.apache.struts.action.mapping.instance'].scope}"
/>

<c:if test="${formScope=='request'}">
        <c:set
                var="form"
                value="${requestScope[formName]}" scope="request" />
</c:if>
<c:if test="${formScope=='session'}">
        <c:set
                var="form"
                value="${sessionScope[formName]}" scope="request" />
</c:if>
--- code end ---

I usually place this code in a jsp and include it my page when i need to
expose the FormBean easily to the page.

ex. <jsp:include page="/jsp/common/form.jsp" />

Then i use the following syntax in my page:

<c:out value="${form.myValue}"/>

This would allow you to use all the jstl stuff to format values stored in
your FormBean.

Brandon Goodin


-----Original Message-----
From: Sasha Borodin [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 27, 2003 9:29 PM
To: Struts Users Mailing List
Subject: Re: Formatting form data inside the *view* (JSP's)


That's what I use when just outputting the contents of a bean; but I'm trying to format the data in form fields.

If I can't combine <html:text> and <bean:write> (or JSTL's <fmt:format>)
tags, is there another way to achieve this?

Thanks,

-Sasha

On 8/27/03 11:17, "Steve Raeburn" <[EMAIL PROTECTED]> wrote:


The Struts <bean:write> tag offers a format attribute (or

formatKey if you


want to use a resource file).
But JSTL would be a better option if you can use it in your environment.

Steve

http://www.ninsky.com/struts/




-----Original Message-----
From: Sasha Borodin [mailto:[EMAIL PROTECTED]
Sent: August 27, 2003 8:43 AM
To: Struts Users Mailing List
Subject: Formatting form data inside the *view* (JSP's)


Thought I'd throw this out in the middle of the week again...


Kind of a conceptual question:  how do you format Dates, Numbers,
Currencies, etc. for *form fields* inside the JSP?

I know I could do in in the ActionForm getters, but:
   1.  I don't know the locate of the user at that point
   2.  I'd have to recompile the ActionForm every time I want

to make a


change to the *view* - seems like a bad practice.

What I'm looking to achieve is something similar to

<fmt:format> JSTL tag,


where you can specify a format mask, or even a format "style" defined
elsewhere.

Thanks,

-Sasha

On 8/22/03 12:30, "Sasha Borodin" <[EMAIL PROTECTED]> wrote:


I would like to state a basic assumption I deduced in learning

struts, then


pose a question.

Assumption: ActionForm property getters and setters should

return and take


Strings.

My initial impulse was to try passing the actual data types

(Dates, Numbers,


etc.); however, the Struts mechanism seems to pass Strings to

the ActionForm


setter methods on form submission (which throws a conversion

Exception of


course). Then I tried making the setters take Strings, and

getters return


the actual data types, but this seemed to confuse the introspection
mechanism; plus I didn't see any way to apply formatting inside the
html:text tags (like you can in JSTL's fmt:format tags).

Question: How does one handle formatting data (custom

formatting or i18n)


for (pre/re)population of a form?

Ex.: An update form; a user's information is loaded from the

database into


classes (Strings, Dates, Numbers, etc.). If you want to format

this data,


you have to do it in the Model, as the ActionForm only takes and gives
Strings - which seems to be a Bad Practice.  Even if you had

additional


special setters for the explicit purpose of populating the

ActionForm from


original data types, you still don't know what Locale the

client is from.


Is my assumption incorrect? Is there a basic flaw in my

understanding of


the use of ActionForm? Or there an actual short-coming, and

workaround?


In short, How Can You Format Data For Strut's Form Tags Inside

The Actual


JSP :-) ?

Thank you for any input.

-Sasha

-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>



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



Reply via email to