This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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: 61315
    
  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