You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Phan, Hienthuc T" <hi...@merck.com> on 2009/03/14 01:11:27 UTC

Required attribute

Is there a way to change the required attribute value in textfield,
textarea, etc. from asterisk (*) to some other value like (required)?  
I'm using Struts 2.1.6

-Hien
Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or
MSD and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and
then delete it from your system.

Re: Required attribute

Posted by Wes Wannemacher <we...@wantii.com>.
On Friday 13 March 2009 20:11:27 Phan, Hienthuc T wrote:
> Is there a way to change the required attribute value in textfield,
> textarea, etc. from asterisk (*) to some other value like (required)?
> I'm using Struts 2.1.6
>

You can change the labelSeparator, but the asterisk is hardcoded. It'd 
probably be quite easy to copy controlheader-core.ftl and make the change for 
your project. 

-Wes

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Required attribute

Posted by Wes Wannemacher <we...@wantii.com>.
On Friday 13 March 2009 20:49:34 Martin Gainty wrote:
>
> as I dont see required attribute (but I do see dynamic attributes=true)
> do you want a required attribute in TextField
> ?
> Martin

Martin, it's there, likely via inheritance. I'm pretty sure it's available on 
all UIBeans. As Dave and I mentioned, it's rendered in controlheader-core.ftl. 
The required parameter is a boolean, and if true, will place an asterisk 
between the label text and label separator. IMO, if it were requested that the 
asterisk be configurable, I'd be somewhat against it. The behavior of adding 
an asterisk seems to be specific to the xhtml theme, and it would be trivial 
to copy the controlheader-core.ftl out of the jar and place it on the 
classpath with something other than an asterisk... Adding another attribute to 
a set of tags that already have so many for such an easy change is overkill 
(of course, that doesn't stop someone else from making the change).

-Wes

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Required attribute

Posted by Martin Gainty <mg...@hotmail.com>.
TextField.java contents:

/*
 * $Id: TextField.java 651946 2008-04-27 13:41:38Z apetrelli $
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.struts2.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import com.opensymphony.xwork2.util.ValueStack;
/**
 * <!-- START SNIPPET: javadoc -->
 * Render an HTML input field of type text</p>
 * <!-- END SNIPPET: javadoc -->
 *
 * <p/> <b>Examples</b>
 * <p/>
 * <!-- START SNIPPET: exdescription -->
 * In this example, a text control for the "user" property is rendered. The label is also retrieved from a ResourceBundle via the key attribute.
 * <!-- END SNIPPET: exdescription -->
 * <pre>
 * <!-- START SNIPPET: example -->
 * &lt;s:textfield key="user" /&gt;
 * <!-- END SNIPPET: example -->
 * </pre>
 *
 * <pre>
 * <!-- START SNIPPET: example2 -->
 * &lt;s:textfield name="user" label="User Name" /&gt;
 * <!-- END SNIPPET: example -->
 * </pre>

 */
@StrutsTag(
    name="textfield",
    tldTagClass="org.apache.struts2.views.jsp.ui.TextFieldTag",
    description="Render an HTML input field of type text",
    allowDynamicAttributes=true)
public class TextField extends UIBean {
    /*** The name of the default template for the TextFieldTag */
    final public static String TEMPLATE = "text";

    protected String maxlength;
    protected String readonly;
    protected String size;

  public TextField(ValueStack stack, HttpServletRequest request, HttpServletResponse response)    
{
        super(stack, request, response);
  }

    protected String getDefaultTemplate() {
        return TEMPLATE;
    }

    protected void evaluateExtraParams() {
        super.evaluateExtraParams();

        if (size != null) {
            addParameter("size", findString(size));
        }

        if (maxlength != null) {
            addParameter("maxlength", findString(maxlength));
        }

        if (readonly != null) {
            addParameter("readonly", findValue(readonly, Boolean.class));
        }
    }

    @StrutsTagAttribute(description="HTML maxlength attribute", type="Integer")
    public void setMaxlength(String maxlength) {
        this.maxlength = maxlength;
    }

    @StrutsTagAttribute(description="Deprecated. Use maxlength instead.", type="Integer")
    public void setMaxLength(String maxlength) {
        this.maxlength = maxlength;
    }

    @StrutsTagAttribute(description="Whether the input is readonly", type="Boolean", defaultValue="false")
    public void setReadonly(String readonly) {
        this.readonly = readonly;
    }

    @StrutsTagAttribute(description="HTML size attribute",  type="Integer")
    public void setSize(String size) {
        this.size = size;
    }
}

--------TextFieldTag.java
/*
 * $Id: TextFieldTag.java 651946 2008-04-27 13:41:38Z apetrelli $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.struts2.views.jsp.ui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.apache.struts2.components.TextField;
import com.opensymphony.xwork2.util.ValueStack;

/** @see TextField  */
public class TextFieldTag extends AbstractUITag {

    private static final long serialVersionUID = 5811285953670562288L;
    protected String maxlength;
    protected String readonly;
    protected String size;

    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
        return new TextField(stack, req, res);
    }

    protected void populateParams() {
        super.populateParams();

        TextField textField = ((TextField) component);
        textField.setMaxlength(maxlength);
        textField.setReadonly(readonly);
        textField.setSize(size);
    }

    /*** @deprecated please use {@link #setMaxlength} instead */
    public void setMaxLength(String maxlength) {
        this.maxlength = maxlength;
    }

    public void setMaxlength(String maxlength) {
        this.maxlength = maxlength;
    }

    public void setReadonly(String readonly) {
        this.readonly = readonly;
    }

    public void setSize(String size) {
        this.size = size;
    }
}
-----------end TextFieldTag.java

as I dont see required attribute (but I do see dynamic attributes=true)
do you want a required attribute in TextField
?
Martin 
______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 




> Subject: Required attribute
> Date: Fri, 13 Mar 2009 20:11:27 -0400
> From: hienthuc_phan@merck.com
> To: user@struts.apache.org
> 
> 
> Is there a way to change the required attribute value in textfield,
> textarea, etc. from asterisk (*) to some other value like (required)?  
> I'm using Struts 2.1.6
> 
> -Hien
> Notice:  This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
> New Jersey, USA 08889), and/or its affiliates (which may be known
> outside the United States as Merck Frosst, Merck Sharp & Dohme or
> MSD and in Japan, as Banyu - direct contact information for affiliates is
> available at http://www.merck.com/contact/contacts.html) that may be
> confidential, proprietary copyrighted and/or legally privileged. It is
> intended solely for the use of the individual or entity named on this
> message. If you are not the intended recipient, and have received this
> message in error, please notify us immediately by reply e-mail and
> then delete it from your system.

_________________________________________________________________
Windows Liveā„¢ Contacts: Organize your contact list. 
http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009

RE: Required attribute - SOLVED

Posted by "Phan, Hienthuc T" <hi...@merck.com>.
Thank you Dave.
That is the file I was looking for.  Initially I looked in the
common-attributes.ftl and couldn't find it.  

-Hien

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Friday, March 13, 2009 5:26 PM
To: Struts Users Mailing List
Subject: Re: Required attribute

Phan, Hienthuc T wrote:
> Is there a way to change the required attribute value in textfield,
> textarea, etc. from asterisk (*) to some other value like (required)?

> I'm using Struts 2.1.6

IIRC the "*" comes from the template file; it should probably be 
definable. Check controlheader-core.ftl.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or
MSD and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and
then delete it from your system.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Required attribute

Posted by Dave Newton <ne...@yahoo.com>.
Phan, Hienthuc T wrote:
> Is there a way to change the required attribute value in textfield,
> textarea, etc. from asterisk (*) to some other value like (required)?  
> I'm using Struts 2.1.6

IIRC the "*" comes from the template file; it should probably be 
definable. Check controlheader-core.ftl.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org