Posted
Filed under JSP, JAVA
<html:option value="<bean:write property='best' name='supplier'/>"><bean:write property="supplierName" name="supplier"/></html:option>

option 테그에 value값을 넣기 위해서 bean:write를 사용 하게 되면, 값이 그대로 들어 가게 된다.  value=""에는 어떤 테그도 들어 갈 수 없다..
그럼으로, <bean:define>테그를 이용하여 변수를 생성 하여 값을 넣어 주면 된다.

<html:select property="homeContext">
<html:option value=""><bean:message key="home.context" /></html:option>
<logic:iterate name="supplierlst" id="supplier" scope="request">
<bean:define id="supplierValue" ><bean:write property="best" name="supplier"/></bean:define>
<html:option value="<%=supplierValue%>"><bean:write property="supplierName" name="supplier"/>(<bean:write property="best" name="supplier"/>)</html:option>
</logic:iterate>
</html:select>


[document]http://struts.apache.org/1.x/struts-taglib/tagreference.html#bean:define

<bean:define>

Define a scripting variable based on the value(s) of the specified bean property.

Create a new attribute (in the scope specified by the toScope property, if any), and a corresponding scripting variable, both of which are named by the value of the id attribute. The corresponding value to which this new attribute (and scripting variable) is set are specified via use of exactly one of the following approaches (trying to use more than one will result in a JspException being thrown):

  • Specify a name attribute (plus optional property and scope attributes) - The created attribute and scripting variable will be of the type of the retrieved JavaBean property, unless it is a Java primitive type, in which case it will be wrapped in the appropriate wrapper class (i.e. int is wrapped by java.lang.Integer).
  • Specify a value attribute - The created attribute and scripting variable will be of type java.lang.String, set to the value of this attribute.
  • Specify nested body content - The created attribute and scripting variable will be of type java.lang.String, set to the value of the nested body content.

If a problem occurs while retrieving the specified bean property, a request time exception will be thrown.

The <bean:define> tag differs from <jsp:useBean> in several ways, including:

  • Unconditionally creates (or replaces) a bean under the specified identifier.
  • Can create a bean with the value returned by a property getter of a different bean (including properties referenced with a nested and/or indexed property name).
  • Can create a bean whose contents is a literal string (or the result of a runtime expression) specified by the value attribute.
  • Does not support nested content (such as <jsp:setProperty> tags) that are only executed if a bean was actually created.

USAGE NOTE - There is a restriction in the JSP 1.1 Specification that disallows using the same value for an id attribute more than once in a single JSP page. Therefore, you will not be able to use <bean:define> for the same bean name more than once in a single page.

USAGE NOTE - If you use another tag to create the body content (e.g. bean:write), that tag must return a non-empty String. An empty String equates to an empty body or a null String, and a new scripting variable cannot be defined as null. Your bean must return a non-empty String, or the define tag must be wrapped within a logic tag to test for an empty or null value.

USAGE NOTE - You cannot use bean:define to instantiate a DynaActionForm (type="org.apache.struts.action.DynaActionForm") with the properties specified in the struts-config. The mechanics of creating the dyna-properties is complex and cannot be handled by a no-argument constructor. If you need to create an ActionForm this way, you must use a conventional ActionForm.

See the Bean Developer's Guide section on bean creation for more information about these differences, as well as alternative approaches to introducing beans into a JSP page.

Can contain: JSP

Attributes

Name Description Type
id*

Specifies the name of the scripting variable (and associated page scope attribute) that will be made available with the value of the specified property.

String
name

Specifies the attribute name of the bean whose property is accessed to define a new page scope attribute (if property is also specified) or the attribute name of the bean that is duplicated with the new reference created by this tag (if property is not also specified). This attribute is required unless you specify a value attribute or nested body content.

String
property

Specifies the name of the property to be accessed on the bean specified by name. This value may be a simple, indexed, or nested property reference expression. If not specified, the bean identified by name is given a new reference identified by id.

String
scope

Specifies the variable scope searched to retrieve the bean specified by name. If not specified, the default rules applied by PageContext.findAttribute() are applied.

String
toScope

Specifies the variable scope into which the newly defined bean will be created. If not specified, the bean will be created in page scope.

String
type

Specifies the fully qualified class name of the value to be exposed as the id attribute.

String
value

The java.lang.String value to which the exposed bean should be set. This attribute is required unless you specify the name attribute or nested body content.

2010/02/09 16:36 2010/02/09 16:36