在javascript数组中获取bean数据

时间:2013-07-14 13:59:41

标签: java javascript jsf-2 jstl javabeans

我正在制作图像滑块,我想从服务器中提取图像名称。

对于动态,下面是我的。

<script type="text/javascript">

    var firstreel=new reelslideshow({
        wrapperid: "myreel", //ID of blank DIV on page to house Slideshow
        dimensions: [800, 600], //width/height of gallery in pixels. Should reflect dimensions of largest image
        imagearray: [
            ["http://www.almaktab.com/iPhoneApp/gallery/image001.jpg"], //["image_path", "optional_link", "optional_target"]
            ["http://www.almaktab.com/iPhoneApp/gallery/image002.jpg", "http://www.almaktab.com/iPhoneApp/gallery/image002.jpg", "_new"],
            ["http://www.almaktab.com/iPhoneApp/gallery/image003.jpg"],
            ["http://www.almaktab.com/iPhoneApp/gallery/image004.jpg"] 
            //-no trailing comma after very last image element!
        ],
        displaymode: {type:'auto', pause:4000, cycles:2, pauseonmouseover:true},
        orientation: "h", //Valid values: "h" or "v"
        persist: true, //remember last viewed slide and recall within same session?
        slideduration: 300 //transition duration (milliseconds)
    })

</script>

现在我想用我在数据库上的图像名称替换imagearray

因此,我所做的就在下面。

xmlns:c="http://java.sun.com/jsp/jstl/core"

<h:body>
    <f:metadata>
        // pulling image names
        <f:event type="preRenderView" listener="#{FullScopeBens.pullMyImageNames()}"/>
    </f:metadata>

<script type="text/javascript">
    alert('perfect = ');

    var data = {
            <c:forEach items="${FullScopeBens.myDealsList}" var="ctag" varStatus="loop">
            '${ctag.imagePath}': '${ctag.imagePath}${!loop.last ? ',' : ''}
            </c:forEach>
        };
    alert('perfect = ' + data);
</script>

并计划将imagearray:...替换为imagearray:data

但它不起作用。

我打印时

<c:forEach items="#{FullScopeBens.myDealsList}" var="item">
    ${item.id}==${item.title}
</c:forEach>

我获得了该图片的正确ID和标题。

任何想法如何在javascript中获取图像路径。

Reference for above loop

即使我尝试下面的链接。但仍然无法正常工作。

https://community.jboss.org/thread/160332

(寻找3. Dec 23, 2010 8:31 AM (in response to Eswara MoorthyNEC)


答案

以下链接帮我回答。

https://stackoverflow.com/a/4143187/1066828

1 个答案:

答案 0 :(得分:1)

以下链接帮我回答。

https://stackoverflow.com/a/4143187/1066828

所以我正在做的是将bean数据分配给textfield并通过javascript我从textfield获取数据并在数组中使用它。