struts taglib: set request parameter in jsp

2.4k views Asked by At

i iterate a list of news on a page with two buttons there: edit and view,so i want to set news id to request scope to use it then in edit action, here is the form

<html:form action="NewsAction">
        <div class="news">
            <fieldset>
                <logic:iterate name="newsList" id="news">
                    <legend>
                        <bean:write name="news" property="newsTitle" />
                    </legend>
                    <p>
                        <bean:write name="news" property="newsId"/>
                        <bean:write name="news" property="newsTitle" />

                        <bean:write name="news" property="newsBrief" />
                        <bean:write name="news" property="newsDate" />
                    </p>


                    <html:submit property="method">view</html:submit>
                    <html:submit property="method" value="edit" />
                    <html:submit property="method">delete</html:submit>
                </logic:iterate>

            </fieldset>
        </div>
    </html:form>

i tried <html:hidden property="nnews" value="${news.newsId}" />
and

<jsp:setProperty property="newsId" name="news" param="newsInstanceId" />

using first one i got ${news.newsId} in request parameter, and using second null

2

There are 2 answers

0
DeadKennedy On BEST ANSWER

problem is seems to be solved: i declared in web.xml version 2.5 (it was 2.3)

<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="Your_WebApp_ID"
    version="2.5">

and added to @page isELIgnored="false"

6
Susie On

On your first approach:

Change this line:

<html:hidden property="nnews" value="${news.newsId}" />

To:

 <html:hidden property="nnews" value="<bean:write name="news" property="newsId"/>" />