views:

96

answers:

2

Hi,

I am aware that this is somewhat a re-post, but I feel like re-posting my question will make things more clear.

Here is the code for my table in my JSP page:

<display:table name="table" pagesize="25" requestURI="">
<display:column title="Action" >
    <s:form theme="simple">
        <s:hidden key="cpc" />
        <s:submit action="remove" value="Remove" 
        onclick="return confirm('Are you sure you want to delete this item?');"/>
        <s:submit action="displayEdit" value="Edit"/>
    </s:form>
</display:column>
<display:column property="cpc" title="CPC" sortable="true" headerClass="sortable"/>
<display:column property="companyName" title="Company Name" sortable="true" headerClass="sortable"/>
<display:column property="eventType" title="Event Type" sortable="true" headerClass="sortable"/>
<display:column property="industryType" title="Industry Type" sortable="true" headerClass="sortable"/>
<display:column property="previousEvents" sortable="true" headerClass="sortable"/>
<display:column property="creditNotifications" sortable="true" headerClass="sortable"/>
<display:column property="interimNotifyEnterprise" sortable="true" headerClass="sortable"/>
</display:table>

The source for the table is an ArrayList, where TableRow is a wrapper class of all the various fields (and I have getters and setters for all the fields). Now when I check my HTML source code, I see this for the hidden field:

<input type="hidden" name="cpc" value="" id="displayResults_cpc"/>

For some reason, there is no value to be found... It was working fine before I used Displaytag, and I do have a getter and setter in my Action class (right now it returns an empty String).

Edit: This is the HTML code for the first two rows:

<tr class="odd">
<td>

<form id="displayResults" name="displayResults" onsubmit="return true;" action="/CompanyNameTableManager/displayResults.action;jsessionid=566617D98154AB762002B06D9D1087CD" method="post">
        <input type="hidden" name="cpc" value="" id="displayResults_cpc"/>
        <input type="submit" id="displayResults_remove" name="action:remove" value="Remove" onclick="return confirm('Are you sure you want to delete this item?');"/>

        <input type="submit" id="displayResults_displayEdit" name="action:displayEdit" value="Edit"/>

    </form>  
</td>
<td>10.1.1</td>
<td>Comapny A</td>
<td>abc</td>
<td>123</td>
<td>true</td>
<td>true</td>

<td>true</td></tr>
<tr class="even">
<td>

<form id="displayResults" name="displayResults" onsubmit="return true;" action="/CompanyNameTableManager/displayResults.action;jsessionid=566617D98154AB762002B06D9D1087CD" method="post">
        <input type="hidden" name="cpc" value="" id="displayResults_cpc"/>
        <input type="submit" id="displayResults_remove" name="action:remove" value="Remove" onclick="return confirm('Are you sure you want to delete this item?');"/>

        <input type="submit" id="displayResults_displayEdit" name="action:displayEdit" value="Edit"/>

    </form>
</td>
<td>10.1.2</td>
<td>Comapny B</td>
<td>abc</td>
<td>123</td>
<td>true</td>
<td>false</td>
<td>false</td></tr>
A: 

I think what's probably happening is that the row-specific requirements for Struts 2 and the Display taglib are interacting poorly, i.e. that the other taglib is doing its own row-by-row processing, and the OGNL expression for 'cpc' isn't being evaluated properly, because the row isn't being properly pushed onto the value stack (if you don't understand what I mean, it's not crucial).

Since you have the CPC value in another column, is it possible for you to use Javascript in an onClick (or onLoad) of the buttons to retrieve the value from the adjacent field?

Shawn D.
Hi Shawn, could you provide a simple example on how I would do something along those lines? I've never really dealt with Javascript before...
Raymond
You sure are lucky to get to learn all of these things at once. :-)Yeah, I'll see what I can come up with in a few minutes.
Shawn D.
Can you paste a bit of the row's generated HTML so I can give you some Javascript? I'm just not sure what the 'real' IDs will be in your example.Thanks.
Shawn D.
Ah darn, I can't access my webapp right now (it's on the network at work), I'll paste it tomorrow morning. And I guess I am "lucky" to be learning all this stuff at once? haha
Raymond
Hi Shawn, I edited my original post to show the HTML generated.
Raymond
Can you include just a little more to show the value of the 'real' CPC column so I know the ID? Also, there doesn't seem to be anything row-specific in the IDs generated. Do you only have one row in this table?
Shawn D.
Hi Shawn, sorry about the confusion, I edited my post to include the 1st two rows (excluding the header). The CPC field would be 10.1.1 and 10.1.2 for the 1st and 2nd rows, respectively. The CPC is unique to each row, so that's probably the easiest identifier I could use to denote uniqueness in the rows.
Raymond
Nevermind, I found an alternate solution that works.
Raymond
A: 

I guess I copped out from using buttons, but if anyone is curious, here is what I ended up using instead:

<s:form theme="simple" method="post">
<display:table name="table" pagesize="25" requestURI="" uid="row">
<display:column title="Select">
    <s:checkbox name="checked[%{#attr.row_rowNum - 1}]" fieldValue="%{#attr.row.cpc}" theme="simple"/>
</display:column>
<display:column property="cpc" title="CPC" sortable="true" headerClass="sortable"/>
<display:column property="companyName" title="Company Name" sortable="true" headerClass="sortable"/>
<display:column property="eventType" title="Event Type" sortable="true" headerClass="sortable"/>
<display:column property="industryType" title="Industry Type" sortable="true" headerClass="sortable"/>
<display:column property="previousEvents" sortable="true" headerClass="sortable"/>
<display:column property="creditNotifications" sortable="true" headerClass="sortable"/>
<display:column property="interimNotifyEnterprise" sortable="true" headerClass="sortable"/>
</display:table>
    <s:submit action="remove" value="Remove" 
    onclick="return confirm('Are you sure you want to delete this item / these items?');"/>
    <s:submit action="displayEdit" value="Edit"/>
    <s:submit value="Add New Row" action="displayAdd"/>
</s:form>
Raymond