Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

c:set value is not working when trying to retrieve using scriptlet  RSS feed

 
Khyathi nyala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am not able to get the value using pageContext.getAttribute("pageName") when setting using <c:set. The following are the steps iam doing.


<% pageContext.setAttribute("pagename",pageNameStringValue); %>

<%@ page isELIgnored="false" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<s:bean name="com.abc.example.console.data.CommonDataService" var="dataobj">
<c:forEach var="data" items="dataobj.dataList"> Here getting the datalist from the CommonDataService which of type data bean
<c:choose>
<c:when test="${#data.pageName==pageScope.pageNameStringValue}"> Here checking against the script value above
<c:set var="cpageName" scope="page" value="${#data.pageName}" /> Here trying to set the cpageName variable to the value of the pageName from dataList

<%
System.out.println ("Displaying Page name: "+pageContext.getAttribute("cpageName"));
%>

The PROBLEM is <c:set value is not setting up the cpageName at page context level and when i do System.out, I am getting NULL value.
I am using struts2, jstl1.2.
Can anyone please let me know as soon as possible, why is it not setting up at the page scope.

Thanks so much.....

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens if you try to output this


Also, please always put your code between the code tags.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"kals ny", please check your private messages for an important administrative matter.
 
Khyathi nyala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did try doing <c:out var="pageName" value="${#data.pageName}".
Its just printing #data.pageName.

If I do like this <c:out var="pageName" value="${data.pageName}", the compiler complains that pageName property not found.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Khyathi ny", please check your private messages for an important administrative matter. Again.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what that # is doing there in the first place.

Khyathi ny wrote:.. the compiler complains that pageName property not found.

Does the bean have a pageName property?
 
Khyathi nyala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Now the code working. After your post, I checked my code again for the # (As I was using s:iterator in the begining, i was reading the values using #dataobj...) and removed it.
And one more mistake, I was doing is, not reading as an expression the items attribute.

<c:forEach var="data" items="${dataobj.dataList}">

Now "data" is of type list and reads all the properties from the bean and I am able to get the values using pageContext.getAttribute("pageName") as I am setting up the values at the page level.

Thanks so much...........for the help.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!