Abhishek Singh
Abhishek Singh

Reputation: 1517

<s:url> namespace attribute in Struts2

My Code is:

<s:url action="work-items_input" includeParams="get" var="wiLink"  namespace="">
    <s:param name="workItemVO.workItemId" value="'5'"></s:param>
</s:url>    
<s:a action="%{wiLink}" namespace="/myaccount"><s:property value="subject"/></s:a>

In my application's ContextRoot is "pmp". Here above is generating link as

/pmp//pmp/myaccount/work-items_input.action?ajaxRequest=true&workItemVO.workItemId=5

above we can see context path is coming twice. /pmp//pmp... this is wrong. How to remove one extra context path?

Upvotes: 0

Views: 4688

Answers (3)

John
John

Reputation: 1

It does not work because of the & so you must replace all occurrences to &.

<td align="right">
   <s:url action="collectionSummary" var="csUrl">  
    <s:param name="collectionSummary.name">
        <s:property value="debtCase.origNameTxt"/></s:param>
    <s:param name="socSecNum">
        <s:property value="debtCase.socSecNum"/></s:param>
    <s:param name="debtCaseId"><s:property value="debtCase.ID"/></s:param>
    <s:param name="nomenu">Y</s:param>
   </s:url>
   <s:a    href="#" 
           onclick="window.open(clearURL('%{csUrl}'));" <------- 
           title="View Collection Summary" 
           class="screen_link">
   <s:text name="link.CollSumm"/></s:a>
</td>


function clearURL(element){
    return element.replace(new RegExp('&amp;', 'g'),"&");
}

Upvotes: 0

Abhishek Singh
Abhishek Singh

Reputation: 1517

Above Accepted answer is absolutely correct, no doubt. But we can use "includeContext="false" also in <s:url> as an alternate with action attribute instead href.

<s:url action="work-items_input" includeParams="get" var="wiLink"  namespace="/myaccount" includeContext="false">
    <s:param name="workItemVO.workItemId" value="'5'"></s:param>
</s:url>    
<s:a action="%{wiLink}" namespace=""><s:property value="subject"/></s:a>

Upvotes: 0

Andrea Ligios
Andrea Ligios

Reputation: 50203

Remove the action and namespace attributes from the <s:a> tag, and use instead the <s:url>'s one with the href attribute:

<s:url action="work-items_input" includeParams="get" var="wiLink"  namespace="/myaccount">
    <s:param name="workItemVO.workItemId" value="'5'"></s:param>
</s:url>    
<s:a href="%{wiLink}"><s:property value="subject"/></s:a>

That should be enough.

Upvotes: 1

Related Questions