views:

29

answers:

3

I would like to know how the default value can be set in textarea , the scenario would be after a page refresh , or fail of validation bedore save operation.

<s:textarea name="desc" value="" theme="xhtml" required="true" cssClass="text textarea small"/>

value="<%= "Default" %>" , this code is not working out.

A: 

Well one of the way would be use Javascript function to load Default value on pageload event... Though I am not sure why your tag is not working

VinAy
A: 

Try to initialize the object linked to the field in the previous action method.

In your java File:

X object = new X() ;
object.setDesc("");
request.setAttribute("theFormObject",object);

In your JSP:

<s:textarea name="theFormObject" property="desc" ... />
Fred
A: 

Perhaps I'm missing something, but IMO this is the same as for any field: the value attribute of a Struts2 tag looks up the respective property in your stack. In the typical scenario, when you type, say, <s:textarea value="comment" ..> Struts2 will use the MyAction.getComment() and MyAction.setComment() to read/write the textarea value. Then, you just have to assign a default value for the attribute in your action -which, BTW, is conceptually the right way.

  public class MyAction extends ActionSupport { 
     public final static String DEFAULT_COMMENT = "Default value...";

     private String comment = DEFAULT_COMMENT;
     //... getters setters follow

  }
leonbloy