Search code examples
jspstruts2jstlognl

How to avoid Default value (com.opensymphony.xwork2.DefaultTextProvider@28e67c) for textfield in struts2


I am working on a struts2 application. In one of the JSP page I have a textfield tag for which value is retrieved from OGNL expression. When the OGNL expression value is empty it is showing com.opensymphony.xwork2.DefaultTextProvider@28e67c in the text field. I do not want this default value, if the value is not available I want to show just empty textbox. Below is my code. Please help.

In the below example when the sampletext is empty I get some default value for textfield as com.opensymphony.xwork2.DefaultTextProvider@28e67c but I want to show it blank if it is empty.

JSP:

<%@ page language="java" errorPage="Error.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
 <%
  String sampletext = ""; 
 %>
 <html>
  <head>
  </head>
   <body>
     <s:set var="remarks"><%=sampletext%></s:set>
     <s:textfield value="%{remarks}" type="text"></s:textfield>
   </body>
 </html>

Solution

  • You should not use scriptlets in the code as @AleksandrM is mentioned, but you could use JSTL in the following way

     <c:set var="remarks"><%=sampletext%></c:set>
     <s:textfield value="%{#attr.remarks}"/>