File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Dynamically setting property name in jsp:setProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Dynamically setting property name in jsp:setProperty" Watch "Dynamically setting property name in jsp:setProperty" New topic
Author

Dynamically setting property name in jsp:setProperty

anindya halder
Greenhorn

Joined: Oct 03, 2012
Posts: 7
Hi Everyone...

I am trying to set property name of the bean dynamically in <jsp:setProperty> .

I found out that when a field value is empty,bean is not called implicitly by <jsp:setProperty name="someName" property="*" />.
Therefore I am trying to do it forcefully ......
As there are two many fields I dont want to do it individually and trying to do it dynamically like this........


<%

for(Enumeration e = request.getParameterNames(); e.hasMoreElements(); ){
String ParameterNames = (String)e.nextElement();

if (request.getParameter(ParameterNames).equals(""))
%>
<jsp:setProperty name="adetails" property = "<%= ParameterNames %>" value="" /> ;

<%
}
%>



But I am getting an error....
Cannot find any information on property '' in a bean of type 'tdcbeans.ApplicationDetails'

[adetails is the object of 'tdcbeans.ApplicationDetails' class.

Please help.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Are you really using that loop in your JSP ?
Why on earth would anyone want to set an empty property? This is different than an empty value for the property.
That is no way possible and not at all logical.


SCJP, SCWCD.
|Asking Good Questions|
Sai Prasad Sabeson
Greenhorn

Joined: Oct 10, 2011
Posts: 4
I dont think any problem will arise if the field is empty.It wil work anyways.
Things that will happed is that empty field's value will be null if its a string field or its default value is set (in case if its non string var).

Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Sai Prasad Sabeson wrote:Things that will happed is that empty field's value will be null if its a string field or its default value is set (in case if its non string var).

No. If the code tries to assign a blank string, then the value wont be null for a string.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamically setting property name in jsp:setProperty