Just a comment that this type of approach "hard-codes" two pieces of information that are defined in struts-config.xml: the form's scope and its attribute name. If those change in your configuration, you also have to change them in your JSP. The <bean:struts> tag allows you to access that configuration information dynamically. So, the first step is to get a handle to the action mapping that matches the action attribute of your <html:form> tag:

<bean:struts id="parameterMapping" mapping="/parameter"/>

This gets you an ActionConfig instance as a scripting variable and page-scoped attribute. Then, you can access both the scope and attribute name:

<bean:define id="formScope"
             name="parameterMapping"
             property="scope"/>
<bean:define id="formAttribute"
             name="parameterMapping"
             property="attribute"/>

or with JSTL (which only creates scoped attributes, not scripting variables):

<c:set var="formScope" value="${parameterMapping.scope}"/>
<c:set var="formAttribute" value="${parameterMapping.attribute}"/>

At this point, it's a lot easier to use JSTL to get a handle to the actual form:

<c:choose>
  <c:when test="${'request' == formScope}">
    <c:set var="form" value="${requestScope[formAttribute]}"/>
  </c:when>
  <c:otherwise>
    <c:set var="form" value="${sessionScope[formAttribute]}"/>
  </c:otherwise>
</c:choose>

Now you've got a page-scoped attribute for the form. Using JSTL again, you can do something like:

<c:choose>
  <c:when test="${form.structure_changeable == 1}">
    ...
  </c:when>
  <c:otherwise>
    ...
  </c:otherwise>
</c:choose>

Brandon Goodin wrote:
if you are using jstl you can access your form-bean like such if your
form-bean is in the requestScope (specified in the struts-config.xml).

<c:out value="${requestScope.myFormBean.aProperty}"/>

* requestScope = scope the bean has been placed in by the ActionServlet
(specified in the struts-config.xml requestScope or sessionScope)
* myFormBean = the name of your form-bean specified in the struts-config.xml
* aProperty = the name of a property that exists in your form-bean.

Brandon Goodin
Phase Web and Multimedia
PO Box 85
Whitefish MT 59937
P (406) 862-2245
F (406) 862-0354
[EMAIL PROTECTED]
http://www.phase.ws


-----Original Message----- From: Jörg Maurer [mailto:[EMAIL PROTECTED] Sent: Sunday, February 23, 2003 10:19 AM To: Struts Users Mailing List Subject: RE: seeking shortcut name of current FormBean inside every html:from


Hi John, thanks for answering - you might be right on the issue I should use a EL tag instead of scriplet.

What i am basically interested in : When processing a jsp using a
html:form tag, i guess html:form brings the current form bean object
into some scope accessible to my jsp - but under what name does that tag
expose it?

My form bean is defined in struts config as

<form-bean name="ParameterForm"

type="com.ucpmorgen.mobiletix.app.param.ParameterForm">
                </form-bean>

Cause when used (please forgive my ignorance on your EL solution for
now): <% if (ParameterForm.getStructure_changeable().intValue() == 1) {
%> so.. uuupppps ... the jsp compiler always asked for a static method
on ParameterForm. uuupppps , because I suddenly think that naming the
variable like the class of form bean( the name after it is exposed
later), is an most unlucky coincident, isn't it?!?!!? -> if is, then i
should rename the bean name in the struts config.

Anyway, is the exposed from bean cast to the correct type for usage :
- inside EL-Tag you wrote it is correctly typed
- but for scriplet, isn't it just exposed as being of type
java.lang.Object ?!?!


-----Original Message----- From: John Espey [mailto:[EMAIL PROTECTED] Sent: Sonntag, 23. Februar 2003 17:21 To: Struts Users Mailing List Subject: RE: seeking shortcut name of current FormBean inside every html:from


maybe I'm missing something, but if you use an EL tag (like the core:if or core:choose or logic-el:equals) you wouldn't need to do any scriptlet or casting.

<c:if test="${parameterForm.structure_changeable eq 1}">

</c:if>

as far as the constants, i'm not sure I follow.
Hope this helps though...

-----Original Message-----
From: Jörg Maurer [mailto:[EMAIL PROTECTED]
Sent: Sunday, February 23, 2003 8:40 AM
To: Struts Users Mailing List (E-mail)
Subject: seeking shortcut name of current FormBean inside every
html:from


Hi strut-users!


Since this post i have been using massively e.g. <bean:define
id="parameterForm" name="ParameterForm" type="ParameterForm"/>
in my jsp´s to grab the reference to the current FormBean like e.g.

<html:form action="/parameter">
...
        <bean:define id="parameterForm" name="ParameterForm"
type="ParameterForm"/>
        <% if (parameterForm.getStructure_changeable().intValue() == 1)
{ %>
</html:form>

Please mail the applicable "shortcut" name (as i have forgotten the

full


name, has'nt it been sth. like "org.apache.struts....") and in which
class those constants are denoted. Addendum : Once i got that

reference,


do i have to cast that reference to the correct form type - like : <%

if


(((ParameterForm)xxxFromBean).getStructure_changeable().intValue() ==

1)


{ %>


Tanks a lot Jörg


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




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


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



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

-- 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