Jasper server rest_v2 to upload file asking for extra parameters - bash

Using TIBCO JasperReports Server 6.3.0 and adding resources via the rest_v2 endpoint. The resource descriptor for file seems rather simple, and this is the script I am using to test it:
#!/bin/bash
output=$(curl -sX POST "http://localhost:8080/jasperserver/rest_v2/resources/common/someFile.jrtx?createFolders=true" \
-H "Content-Type:application/repository.query+json" \
-H "Accept:application/json" \
-d "{
\"uri\" :\"/common/someFile.jrtx\",
\"label\":\"someFile.jrtx\",
\"description\":\"Some File\",
\"permissionMask\":\"0\",
\"type\":\"jrtx\",
\"content\":\"$(base64 -w 0 /path/to/someFile.jrtx)\"
}" \
--user jasperadmin:jasperadmin)
echo "${output}" | python -m json.tool
The output I am getting for this is puzzling:
[
{
"errorCode": "mandatory.parameter.error",
"message": "A value for the field QueryValue must be set",
"parameters": [
"QueryValue"
]
},
{
"errorCode": "mandatory.parameter.error",
"message": "A value for the field Language must be set",
"parameters": [
"Language"
]
}
]
The descriptor for FILE doesn't mention either of these fields (Language or QueryValue) and I certainly do not have to enter them when manually creating files. What am I doing wrong?
The JRTX file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperTemplate PUBLIC "-//JasperReports//DTD Template//EN" "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">
<jasperTemplate>
<style name="SimpleStyle"/>
<style name="ColumnHeading" hAlign="Center" vAlign="Middle" isBlankWhenNull="true" fontName="Verdana" fontSize="10" isBold="true">
<pen lineWidth="1.0" lineColor="#666565"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</style>
<style name="Title" markup="" fontSize="20" isBold="true"/>
<style name="TableCells" hAlign="Center" vAlign="Middle" isBlankWhenNull="true" fontName="Verdana" fontSize="10" isBold="false">
<pen lineWidth="1.0" lineColor="#CCCCCC"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#CCCCCC"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#CCCCCC"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#CCCCCC"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#CCCCCC"/>
</box>
</style>
<style name="VerticalColumnHeading" hAlign="Center" vAlign="Middle" rotation="Left" fontName="Verdana" fontSize="12" isBold="true"/>
<style name="GroupHeading" hAlign="Left" vAlign="Middle" fontName="Verdana" fontSize="10">
<pen lineWidth="1.0" lineColor="#CCCCCC"/>
</style>
</jasperTemplate>

Wrong content type. Instead of this
-H "Content-Type:application/repository.query+json" \
I should use this:
-H "Content-Type:application/repository.file+json" \

Related

bash rest-api call authentication problem, I propaly use wrong syntax in my rest-api call but can't find the error

I wrote a powershell script for setting downtimes in our monitoring software "checkmk" and now I have to convert that so a bash script because we are switching from windows server to linux.
user will be "XXX" password will be "YYY" and the hostname will be "ZZZ"
For that I used the documentation from CheckMK:
documentation for show sheduled downtimes
documentation for setting a downtime
and in the end it looks like that:
<#
.Synopsis
Downtime per Rest API bei Check MK Setzen
.DESCRIPTION
Doku https://apt-omd-vip.ads.vhv.de/umbrella/check_mk/openapi/#operation/cmk.gui.plugins.openapi.endpoints.downtime.create_host_related_downtime
30 min Downtime Setzen = 1800 sekunden
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function set-Downtime
{
[CmdletBinding()]
[OutputType([int])]
Param
(
$USERNAME="XXX",
$PASSWORD="XXX",
[Parameter(Mandatory=$true)]
$HOSTNAME,
#Zeit soll die Downtime in Minuten angeben, wird dieseer Parameter leer gelassen wird Standdardmäßig 30min verwendet.
[Parameter(Mandatory=$false)]
[Int]$TIME=30
)
Begin
{
}
Process
{
#=============
# Abfrage der DownTimes, sonst kein Connect möglich
#=============
$headers = #{
‘Accept’ = ‘application/json’
‘Authorization’ = “Bearer $USERNAME $PASSWORD”
}
$body = #{
'host_name' = $HOSTNAME
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$result = Invoke-RestMethod -uri “here was a URL” -Headers $headers -Body $body
#write-host($rest_uri)
#=============
# DownTime
#=============
$headers = #{
'Content-Type' = 'application/json'
‘Accept’ = ‘application/json’
‘Authorization’ = “Bearer $USERNAME $PASSWORD”
}
$datum_start = (get-date).AddHours(-2).ToString("u")
$datum_ende = (get-date).AddHours(-2).addminutes($TIME).ToString("u") ;
$comment = "$TIME min Restart Downtime, $EXTRAINFO"
$body =#{
start_time = $datum_start;
end_time = $datum_ende;
comment = $comment;
host_name = $HOSTNAME;
downtime_type = 'host';
} | ConvertTo-Json -Compress
$result = Invoke-RestMethod -Method Post -uri "here was a URL" -Headers $headers -Body $body
}
End
{
}
}
I apologize for the english-german mix in the script but in theory you shouldn't need my comments.
I reconstructed the command from this bash to powershell help blog
Here is one time my bash script hole and after that I will only post the part I changed:
#!/bin/bash
##Variables
base_url='here was a URL'
request_url="$base_url/all"
post_url="$base_url/host"
user="XXX"
passwd="YYY"
hostname="ZZZ"
user_pass="$user:$passwd"
#header=["Accep"t = "application/json"
#"Authorisation" = "Bearer $user $passwd"]
#body1=["host_name" = "ZZZ"]
curl -u $user_pass -X GET --header 'Accept: application/json' -d {'host_name: ZZZ'} 'here was an URL'
as I am still unexperienced in bash I tried my decleration of variables with the '' and "" quotes because I am still not sure when to use what (but thats not the question here)
Answer is following:
{"title": "You need to be authenticated to use the REST API.", "status": 401}
Next thing I tried was a header construct similar to my ps script:
header=( ["Accept"]="application/json" ["Authorization"]="Bearer XXX YYY")
curl --anyauth -X GET --header $header -d {'host_name: ZZZ'} 'here was an URL'
the answer this times was way longer but in the end I got the same error message:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "censored doc url">
<html>
<!-- FileName: index.html
Language: [en]
-->
<!--Head-->
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>McAfee Web Gateway - Notification</title>
<script src="censored" type="text/vascript" ></script>
<link rel="stylesheet" href="censored" />
</head>
<!--/Head-->
<!--Body-->
<body onload="swOnLoad();">
<table class='bodyTable'>
<tr>
<td class='bodyData' background='censored'>
<!--Logo-->
<table class='logoTable'>
<tr>
<td class='logoData'>
<a href='http://www.mcafee.com'>
<img src='censored'>a>
</td>
</tr>
</table>
<!--/Logo-->
<!--Contents-->
<!-- FileName: authenticationrequired.html
Language: [en]
-->
<!--Title-->
<table class='titleTable' background='censored.jpg'>
<tr>
<td class='titleData'>
Authentication Required
</td>
</tr>
</table>
<!--/Title-->
<!--Content-->
<table class="contentTable">
<tr>
<td class="contentData">
You must be authenticated to access this URL.
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
urlprotocol = "http";
statuscode=407;
if(statuscode==401 && urlprotocol == "ftp"){
document.write("<form name=\"ftpform\" method=\"get\" action=\"\">");
document.write("<table class=\"contentData\">");
document.write("<tr><td class=\"contentData\" colspan=2>Please enter youcredentials in the form below and click \"Access FTP\" button if your browser esn't present authentication prompt for FTP sites.</td></tr>");
document.write("<tr><td class=\"contentData\">Username:</td><td><input te=\"text\" id=\"ftpUsername\" name=\"ftpUsername\" size=40 /></td></tr>");
document.write("<tr><td class=\"contentData\">Password:</td><td><input te=\"password\" id=\"ftpPassword\" name=\"ftpPassword\" size=40 /></td></tr>");
document.write("<tr><td class=\"contentData\" colspan=2 align=center><int type=\"button\" onclick=\"redirectToFTP();\" value=\"Access FTP\" /></td></t");
document.write("</table>");
document.write("</form>");
}
function redirectToFTP(){
var username=escape(document.getElementById("ftpUsername").value);
var password=escape(document.getElementById("ftpPassword").value);
location.href = "ftp://"+username+":"+password+"#XXX:80/"
}
</script>
<!--/Content-->
<!--Info-->
<table class="infoTable">
<tr>
<td class="infoData">
<b>URL: </b><script type="censored");</script><br />
</td>
</tr>
</table>
<!--/Info-->
<!--/Contents-->
<!--Policy-->
<table class='policyTable'>
<tr>
<td class='policyHeading'>
<hr>
Company Acceptable Use Policy
</td>
</tr>
<tr>
<td class='policyData'>
This is an optional acceptable use disclaimer that appears on every pageYou may change the wording or remove this section entirely in index.html.
</td>
</tr>
</table>
<!--/Policy-->
<!--Foot-->
<table class='footTable'>
<tr>
<td class='helpDeskData' background='censored'>
For assistance, please contact your system administrator.
</td>
</tr>
<tr>
<td class='footData'>
generated <span id="time">2022-08-09 14:58:22</span> by McAfee Web Gatew
<br />
curl/7.60.0<br />
Node: censored<br />
Client IP: censored<br />
User: <br />
User-Groups: <br />
Authentication Method: <br />
Rule Set: Authentication with Kerberos and NTLM Fallback<br />
Rule: Perform Authentication<br />
</td>
</tr>
</table>
<!--/Foot-->
</td>
</tr>
</table>
</body>
<!--/Body-->
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "censored">
<html>
<!-- FileName: index.html
Language: [en]
-->
<!--Head-->
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>McAfee Web Gateway - Notification</title>
<script src="censored" type="text/vascript" ></script>
<link rel="stylesheet" href="/mwg-internal/de5fs23hu73ds/files/default/styleeet.css" />
</head>
<!--/Head-->
<!--Body-->
<body onload="swOnLoad();">
<table class='bodyTable'>
<tr>
<td class='bodyData' background='censored'>
<!--Logo-->
<table class='logoTable'>
<tr>
<td class='logoData'>
<a href='http://www.mcafee.com'>
<img src='censored'>a>
</td>
</tr>
</table>
<!--/Logo-->
<!--Contents-->
<!-- FileName: authenticationrequired.html
Language: [en]
-->
<!--Title-->
<table class='titleTable' background='/mwg-internal/de5fs23hu73ds/files/defaulimg/bg_navbar.jpg'>
<tr>
<td class='titleData'>
Authentication Required
</td>
</tr>
</table>
<!--/Title-->
<!--Content-->
<table class="contentTable">
<tr>
<td class="contentData">
You must be authenticated to access this URL.
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
urlprotocol = "http";
statuscode=407;
if(statuscode==401 && urlprotocol == "ftp"){
document.write("<form name=\"ftpform\" method=\"get\" action=\"\">");
document.write("<table class=\"contentData\">");
document.write("<tr><td class=\"contentData\" colspan=2>Please enter youcredentials in the form below and click \"Access FTP\" button if your browser esn't present authentication prompt for FTP sites.</td></tr>");
document.write("<tr><td class=\"contentData\">Username:</td><td><input te=\"text\" id=\"ftpUsername\" name=\"ftpUsername\" size=40 /></td></tr>");
document.write("<tr><td class=\"contentData\">Password:</td><td><input te=\"password\" id=\"ftpPassword\" name=\"ftpPassword\" size=40 /></td></tr>");
document.write("<tr><td class=\"contentData\" colspan=2 align=center><int type=\"button\" onclick=\"redirectToFTP();\" value=\"Access FTP\" /></td></t");
document.write("</table>");
document.write("</form>");
}
function redirectToFTP(){
var username=escape(document.getElementById("ftpUsername").value);
var password=escape(document.getElementById("ftpPassword").value);
location.href = "ftp://"+username+":"+password+"#YYY:80/"
}
</script>
<!--/Content-->
<!--Info-->
<table class="infoTable">
<tr>
<td class="infoData">
<b>URL: </b><script type="text/javascript">break_line("http://setDownTim");</script><br />
</td>
</tr>
</table>
<!--/Info-->
<!--/Contents-->
<!--Policy-->
<table class='policyTable'>
<tr>
<td class='policyHeading'>
<hr>
Company Acceptable Use Policy
</td>
</tr>
<tr>
<td class='policyData'>
This is an optional acceptable use disclaimer that appears on every pageYou may change the wording or remove this section entirely in index.html.
</td>
</tr>
</table>
<!--/Policy-->
<!--Foot-->
<table class='footTable'>
<tr>
<td class='helpDeskData' background='/mwg-internal/de5fs23hu73ds/files/deflt/img/bg_navbar.jpg'>
For assistance, please contact your system administrator.
</td>
</tr>
<tr>
<td class='footData'>
generated <span id="time">2022-08-09 14:58:22</span> by McAfee Web Gatew
<br />
curl/7.60.0<br />
Node:censored<br />
Client IP: censored<br />
User: <br />
User-Groups: <br />
Authentication Method: <br />
Rule Set: Authentication with Kerberos and NTLM Fallback<br />
Rule: Perform Authentication<br />
</td>
</tr>
</table>
<!--/Foot-->
</td>
</tr>
</table>
</body>
<!--/Body-->
</html>
{"title": "You need to be authenticated to use the REST API.", "status": 401}
I needed to cut that part because I was over the characterlimit for the post...
I think that my error is not that hard to solve but I dont know enough about bash to search for the right things so please get easy on me. I used bash the first time in june this year so try to keep the answers a bit simpler than to an usual bash user please, thank you in advance for your help and consideration.
Like I guessed my problem was a minor one... only thing wrong was the ":" in my headers, just had to exchange them for "=".
Well got a new problem but I doubt that you guys can help me when I am not allowed to share more information about our server and applications.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
afer that message I did the same thing in the body like in my header but that didnt do the thing.
Here's a rewrite of your script in bash using curl, because it'll be easier to discuss against an example rather than an abstract in comments.
This, at least to my eyes, does exactly what your Powershell script is doing.
#!/bin/bash
url="https://YOUR-URL"
username="XXX"
password="YYY"
hostname="ZZZ"
# first Invoke-RestMethod, which is a GET with JSON...
# -1 means "use TLS1 or newer"
# -XGET is required here to force it to be a request
# that uses GET with a body, since curl would default to POST
# if '-d' is specified
# -w "%{http_code}\n" means output the http code
# if you want to suppress all other output and only
# get the http code output, specify these additional options:
# -o /dev/null -s
curl $url -1 -XGET \
-H "Accept: application/json" \
-H "Authorization: Bearer $username $password" \
-w "%{http_code}\n" \
-d "{ \"host_name\": \"$hostname\" }"
# Downtime Invoke-RestMethod
minutes_diff=30
start_diff=120
# because in your original, you do (now - 2 hours) + $minutes_diff
# so it's just now -(120 - $minutes_diff) minutes
end_diff=$(( 120 - $minutes_diff ))
# This was based on you using the .NET -u specifier which is
# intended for use with UTC DateTime objects
# I don't know if you actually want your timestamps derived
# from UTC time, which is what "-u" does for the date command
start_time=$(date -u -d "$start_diff minutes ago" +"%Y-%m-%d %H:%M:%SZ")
end_time=$(date -u -d "$end_diff minutes ago" +"%Y-%m-%d %H:%M:%SZ")
# you didn't have an EXTRAINFO in your original script
# so I left it out
comment="$minutes_diff min Restart Downtime"
# The -d #- <<-JSON uses a heredoc so I can
# more nicely express the JSON you send
curl $url -1 \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $username $password" \
-w "%{http_code}\n" \
-d #- <<-JSON
{
"start_time": "$start_time",
"end_time": "$end_time",
"comment": "$comment",
"host_name": "$hostname",
"downtime_type": "host"
}
JSON

PKG installer - part of background image is hidden

I'm trying to set a background in .pkg file.
Here's my distribution.xml template file:
<?xml version="1.0" encoding="utf-8"?>
<installer-gui-script minSpecVersion="1">
<title>{{ title }}</title>
<welcome file="welcome.txt" mime-type="text/plain" />
<readme file="readme.txt" mime-type="text/plain" />
<license file="license.txt" mime-type="text/plain" />
<conclusion file="conclusion.txt" mime-type="text/plain" />
<pkg-ref id="{{ identifier }}"/>
<options customize="never" require-scripts="false"/>
<background file="{{ background_filename }}" mime-type="image/{{ background_ext }}"/>
<choices-outline>
<line choice="default">
<line choice="{{ identifier }}"/>
</line>
</choices-outline>
<choice id="default"/>
<choice id="{{ identifier }}" visible="false">
<pkg-ref id="{{ identifier }}"/>
</choice>
<pkg-ref id="{{ identifier }}" version="{{ version }}" onConclusion="none">{{ identifier }}-{{ build_number }}.pkg</pkg-ref>
</installer-gui-script>
It will be rendered from a Python script, and called with productbuild:
background_path = os.path.join(
config_dir,
config['darwin']['installer']['background_path']
)
background_filename = os.path.basename(background_path)
distribution_rendered = self.source.render_template(
self.__osname,
"productbuild/distribution.jinja2",
{
"title": ' '.join(
(
brand_name,
binary_name,
version
)
),
"background_filename": background_filename,
"background_ext": os.path.splitext(background_filename)[1][1:],
"identifier": identifier,
"build_number": build_number,
"version": version
}
)
with open('distribution.xml', 'w') as f:
f.write(distribution_rendered)
os.mkdir('resources')
shutil.copy(background_path, 'resources')
runcmd(("productbuild --distribution distribution.xml "
"--resources resources "
"--package-path {0}.pkg compiled/{0}.pkg").format(filename))
The .pkg file was created successfully except that part of the background image is hidden:
How can I make this transparent, so I can see the hidden part of the backgroud image?

validation using ajax in struts2

I used ajax validation to validate the following
<tr>
<td width="20" style='color: red'>
<img src="images/icon-star.png" width="16" height="16" />
</td>
<td id="lblCustomBillNo" style="width: 15%" class="searchCriteriaCellLbl">
The custom Bill Number
</td>
<td width="5" class="searchCriteriaCellLbl">:</td>
<td class="searchCriteriaCellVal">
<s:textfield id="customBillNo" name="customBillNo" size="20" maxlength="24" style="width: 200px" />
</td>
<td class="errorFlag" style="color: red" valign="middle">
<s:fielderror fieldName="customBillNo" />
</td>
</tr>
<tr>
<td width="20" style='color: red'>
<img src="images/icon-star.png" width="16" height="16" />
</td>
<td id="lblBillNo" style="width: 15%" class="searchCriteriaCellLbl">
<s:property value="%{getText('billNo')}" />
</td>
<td width="5" class="searchCriteriaCellLbl">:
</td>
<td class="searchCriteriaCellVal">
<s:textfield label="billNo" id="billNo" name="billNo" size="20" maxlength="24" style="width: 200px" />
</td>
<td class="errorFlag" style="color: red" valign="middle">
<s:fielderror fieldName="billNo" />
</td>
</tr>
<tr>
<td width="20" style='color: red'>
<img src="images/icon-star.png" width="16" height="16" />
</td>
<td id="lblCarrierNo" style="width: 15%" class="searchCriteriaCellLbl">
The carrier Number
</td>
<td width="5" class="searchCriteriaCellLbl">:
</td>
<td class="searchCriteriaCellVal">
<s:textfield label="carrierNo" id="carrierNo" name="carrierNo" size="20" maxlength="24" style="width: 200px" />
</td>
<td class="errorFlag" style="color: red" valign="middle">
<s:fielderror fieldName="carrierNo" />
</td>
</tr>
I use the following internationalization for errors in golbal i18n file
errors.required=${getText(fieldName)} requireddd
and this validation file
<validators>
<field name="customBillNo">
<field-validator type="requiredstring" short-circuit="true">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="billNo">
<field-validator type="required" short-circuit="true">
<message key="errors.required" />
</field-validator>
</field>
<field name="carrierNo">
<field-validator type="required" short-circuit="true">
<message key="errors.required" />
</field-validator>
</field>
</validators>
and i put this javascript to use ajax validation
function validate(){
//document.all.loading.style.display = 'block';
var searchUrl = 'AddEnteringApproval_approval';
var params = '';
var elemArray = document.mainForm.elements;
for (var i = 0; i < elemArray.length;i++)
{
var element = elemArray[i];
var elementName= element.name;
if(elementName=='formAction')
continue;
params += '&' + elementName+'='+ encodeURIComponent(element.value);
}
params += '&struts.enableJSONValidation=true&struts.validateOnly=true';
createXmlHttpObject(); // this is my function that prepare ajax
sendRequestPost(http_request,searchUrl,false,params);
postValidation();
}
function postValidation() {
var form = $('#mainForm');
var text = http_request.responseText;
//clear previous validation errors, if any
StrutsUtils.clearValidationErrors(form);
alert(text)
//get errors from response
//var text = request.responseText;
var errorsObject = StrutsUtils.getValidationErrors(text);
//show errors, if any
if(errorsObject.fieldErrors)
{
StrutsUtils.showValidationErrors(form, errorsObject);
}
else
{
//good to go, regular submit
form.submit();
}
}
/* This is one of the functions that doesn't work using the simple theme, so I redefined it.
This can be changed to clear the previous errors, as it does in the commented example
cleaning the errors on divErrors.
As I am just showing the messages with alerts I don't need to clear anything,
but the method still need to be redefined, even if it is empty.
*/
StrutsUtils.clearValidationErrors = function(form, errors) {
//clear the div errors
//$('#divErrors').empty();
}
/* This method is responsible to show the messages.
The original versions works with the xhrml and css-xhtml theme but doesn't work with the simple theme
so I override the method with another implementation that shows the messages using alerts.
You can change the implementation to show the messages as you want,
but as the previous method this has to be redefined.
*/
StrutsUtils.showValidationErrors = function(form, errors) {
if(errors.fieldErrors)
{alert((errors.fieldErrors))
for(var fieldName in errors.fieldErrors)
{
alert("errors.fieldErrors[fieldName] " + errors.fieldErrors[fieldName]);
for(var i = 0; i < errors.fieldErrors[fieldName].length; i++)
{
alert('Field ->' + fieldName + '\nError -> ' + errors.fieldErrors[fieldName][i]);
}
}
}
};
but when i execute the code i get no organized JSON text i showed in alert message box, the field name is not like the one in the error message, the second field name is missing, the third field name is cut (i.e. carrierNo becomes rNo ).
can you help me. i want the field name in the JSON error match the error message text
I just figured out what is the problem, but i don't know why it happens and why.
it always remove the first 6 characters. why this happens
well I figured out the problem.
it was a but in org.apache.struts2.interceptor.validation.JSONValidationInterceptor
it removes the 6 first characters because of this incomplete if statement
sb.append((validationAware instanceof ModelDriven) ? ((String)fieldError.getKey()).substring(6) : (String)fieldError.getKey());
this error is fuond in struts 2.1.8
it should be like this
sb.append(((validationAware instanceof ModelDriven)) && (fieldErrorKey.startsWith("model.")) ? fieldErrorKey.substring(6) : fieldErrorKey);
it was corrected in later struts releses. i corrected the problem. and i thought i have to share the information for people who faces the problem.

please help me to create grid by passing parameters to request action

i am applying struts2 jquery grid.the data in the grid will be generated based on the filter selected values and the jsp will be executed where i have written this code.the data type i am using is json and the action is execution here but i want to pass parameters for this action how can i acheive this without including url in same page.even i tried with type="chain",redirect but i am not getting any grid just json data is displaying
*<s:url id="remoteurl" action="gridaction"/>
<s:url id="editurl" action="editaction"/>
<s:url id="selecturl" action="selectaction"/>*
<sjg:grid id="sjgrid" **dataType="json"** href="%{remoteurl}" caption="Grid Model"
gridModel="gridModel" editurl="%{editurl}"
navigator="true"
navigatorSearch="true"
navigatorSearchOptions="{multipleSearch:true}"
navigatorExtraButtons="{
seperator: {
title : 'seperator'
},
hide : {
title : 'Show/Hide',
icon: 'ui-icon-wrench',
topic: 'showcolumns'
},
alert : {
title : 'Alert',
onclick: function(){ alert('Grid Button clicked!') }
}
}"
loadonce="true"
pager="true"
pagerPosition="center"
rowList="5,10,20"
shrinkToFit="true"
altRows="true"
autowidth="true"
filter="true"
>
<sjg:gridColumn name="iduser" title="iduser" key="true" hidden="true"/>
<sjg:gridColumn name="uname" title="Username" editable="true" align="center"
editrules="{required:true}"
/>
<sjg:gridColumn name="passwd" title="Password" editable="true" align="center"
editrules="{required:true}"
/>
<sjg:gridColumn name="country" title="Country" editable="true" align="center"
edittype="select"
editoptions="{dataUrl:'%{selecturl}'}"
/>
<sjg:gridColumn name="contact" title="Contact No" editable="true" align="center"
editrules="{required:true,number:true,integer:true}"
/>
</sjg:grid>
you have to use formIds attribute:
first create a form with the variables you want to send
second reference this form from sjg:grid with the formIds attribute
in the json action you will have all form variables available

How to get value of Itemrenderer

I want to get value of checkbox from the itemrenderer.I have a datagrid with a checkBox as itemrenderer as follows:
<s:DataGrid id="myGrid" dataProvider="{module_DP}" rowHeight="35" fontSize="9"
x="20" y="20" width="184" height="306">
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Access" dataField="access">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:CheckBox label="" click="Check_Click(event)" selected="#{data.access}" horizontalCenter="0"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
The Check_Click() method:
public function Check_Click():void{
trace(I want to get the value of clicked checkbox..in this case "access")
}
I cant figure out the code that I need to put in the trace.
Can someone advise?
You can try:
<s:CheckBox label="" click="Check_Click(event)" selected="#{data.access}" horizontalCenter="0"/>
public function Check_Click(event:MouseEvent):void{
var cb:Checkbox = event.target as CheckBox
trace(cb.selected);
}
The post title was asking a slightly different question "How to get value of Itemrenderer". Access the data property within the renderer, like you do with {data.access}.
To access it from outside:
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import spark.components.gridClasses.IGridItemRenderer;
private function onGridInitialize(event:FlexEvent):void
{
this.addEventListener('moduleItemChange', onModuleItemChange);
}
private function onModuleItemChange(event:Event):void
{
var item:IGridItemRenderer = event.target as IGridItemRenderer;
if(!item || !item.data) { /* deal with this */ }
trace(item.data.access);
}
]]>
</fx:Script>
<s:DataGrid id="myGrid" rowHeight="35" fontSize="9"
x="20" y="20" width="184" height="306"
initialize="onGridInitialize(event)">
<s:dataProvider>
<s:ArrayList>
<fx:Object access="true"/>
<fx:Object access="false"/>
<fx:Object access="false"/>
<fx:Object access="true"/>
<fx:Object access="true"/>
</s:ArrayList>
</s:dataProvider>
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Access" dataField="access">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<fx:Script>
<![CDATA[
private function Check_Click(even:MouseEvent):void
{
dispatchEvent(new Event('moduleItemChange', true));
}
]]>
</fx:Script>
<s:CheckBox label="" click="Check_Click(event)" selected="#{data.access}" horizontalCenter="0"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>

Resources