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 How to assign ${somevalue} to a bean using jsp:setproperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to assign ${somevalue} to a bean using jsp:setproperty" Watch "How to assign ${somevalue} to a bean using jsp:setproperty" New topic
Author

How to assign ${somevalue} to a bean using jsp:setproperty

Ravi Kumar
Greenhorn

Joined: Oct 15, 2007
Posts: 16
Hi,

I'm trying to set a value to the bean.
The value is from DB

<sql:query var="items">
SELECT name FROM emp
</sql:query>

<c:forEach var="row" items="${items.rows}">
<jsp:useBean id="empName" class="test.emp">
<jsp:setProperty name="empName" property="empName" value="${row.name}"/> </jsp:useBean>

The value that is setting is
${row.name}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61057
    
  66

You have a bean named empName and a property named empName. Bad idea. Very confusing and likely to lead to name collisions.

Either use the JSTL or don't. There's no need to use <jsp:setProperty> if <c:set> is available.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ravi Kumar
Greenhorn

Joined: Oct 15, 2007
Posts: 16
Thanks Bear,
I used the following code
<jsp:useBean id="chkBxNm" scope="session" class="TUnit.TUnitNmBean" />
<c:set target="${chkBxNm}" property="TSName" value="${row.TSName}" />
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to assign ${somevalue} to a bean using jsp:setproperty