This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes Scriptlet in STRUTS 2 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 » Frameworks » Struts
Bookmark "Scriptlet in STRUTS 2" Watch "Scriptlet in STRUTS 2" New topic
Author

Scriptlet in STRUTS 2

Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Hi am using a scriptlet in JSP of Struts 2, but am not able to get the value in textfield. Below is the code which i have used



Its showing an error like "Missing quotes for attribute value"
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
You should try <s:textfield value="<%=str %>">.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Surely the tags in Struts2 support EL so you should avoid scriptlets and do something like this instead:

<s:textfield value="${tDate}" />

I'd also be a bit surprised if this really isn't even the best way. Most tag libraries in the popular frameworks pull in data from the request and bind it back automatically. But I don't know enough about Struts2 to say how in this case. But the above example *should* work.


GenRocket - Experts at Building Test Data
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Hi Gregg,

I tried with your statement but its giving error like
<s:textfield value="${tDate}" name="toDate" id="toDate" />


org.apache.jasper.JasperException: /jsp/ToDate.jsp(4,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If the value is an action property just use OGNL. If it's really in the request then also use OGNL.
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
hi david, i have both ways like

<s:textfield value="${tDate}" name="toDate" id="toDate" />

and




Both none of the things had worked, if you dont mind could you give the exact syntax how to use OGNL
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://struts.apache.org/2.x/docs/ognl.html
http://struts.apache.org/2.x/docs/ognl-basics.html
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Hi David,
I tried with the OGNL also but it is not displaying any value, instead of value it is displaying the code.
But if am using property instead of textfield its working fine.




I had used both the ways but still no luck. Instead of value its displaying "#request.hello"

But its working for property




sandy safikri
Greenhorn

Joined: Apr 21, 2010
Posts: 1
hii i have a same problem how to get struts 2 property?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Try wrapping the expression in the OGNL escape %{}.

@Sandy: what's a "Struts 2 property"? In other words, be specific. Better yet, start new threads for new topics, and TellTheDetails.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Kartik: wait, are you trying to access *parameters*?! Use #parameters then, otherwise you're attempting to access *attributes*. But in general you should never need to access a request parameter directly in a JSP-why are you doing this?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

David Newton wrote:@Kartik: wait, are you trying to access *parameters*?! Use #parameters then, otherwise you're attempting to access *attributes*. But in general you should never need to access a request parameter directly in a JSP-why are you doing this?

I hope Kartik is still not stuck with this problem after almost 1 year ...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

LOL, hadn't noticed Sandy woke a sleeper.
 
jQuery in Action, 2nd edition
 
subject: Scriptlet in STRUTS 2