how to change the behaviour of httpservlet to use doPost in adf? - jsf-2

i have button that it's action is to set inlineframe Src attribute in the backing bean , and this the code for the button :
<af:button
<f:setPropertyActionListener target="#{Bean.iframeURL}" value="http://myurl.com/data&user=user&pass=1234"/>
</af:button>
when i press that button a http get request is sent (as in picture) to the url and the respone is rendered on the webpage
<af:inlineFrame styleClass="IFrame" binding="#{Bean.reportFrameUI}" source="#{Bean.iframeURL}"
id="if1"/>
,
i want to override that and force to use doPost as it's done nomraly in HTML forms for eg :
<form action="http://<HOSTNAME>:<PORT>/analytics/saw.dll?" method="post">
<input type="hidden" name="Cmd" value="Answers">
<input type="hidden" name="nqUser" value="<ADMIN_USER>">
<input type="hidden" name="nqPassword" value="<PASSWORD>">
<input type="submit" value="Answers">
</form>

Related

Bind list with missing items, preserve gaps

How can I post a model list with gaps from a MVC webpage, and have it preserve those gaps when accessing it in server code?
For example, I want to post this:
<input type="hidden" name="ImageUrl.Index" value="0" />
<input type="url" name="ImageUrl[0]" value="example0.png" />
<!---->
<input type="hidden" name="ImageUrl.Index" value="2" />
<input type="url" name="ImageUrl[2]" value="example2.png" />
And receive this in the controller:
public ActionResult Save(Gallery model)
{
model.ImageUrl[0]; // "example0.png"
model.ImageUrl[1]; // null
model.ImageUrl[2]; // "example2.png"
}
I already noticed the "Index" hidden value helps send gaps correctly, but currently I'm receiving a list with 2 items, not 3. I would rather avoid declaring a dummy hidden value.

Passing Connectionstring as parameter in SSRS through URL

I am working on an application using Classic ASP and SQL Server 2008 R2. We are using SSRS for the reports. Now the datasource changes depending on the user. I have been using a parameter for the connectionstring. It is working fine but the problem is the connectionstring shows in the URL. Is there a way to hide it? Or is there a better way.
Please Help.
Yes - change the method on your form to POST and use the Request.Form syntax instead of Request.QueryString:
<form id="myForm" method="post" action="myPage.asp">
<label for="txtBox">Type something</label>
<input type="text" id="txtBox" name="txtBox" />
</form>
<%
Dim value
value = Cstr(Request.Form("txtBox"))
If value <> "" then
'Do your processing
End if
%>
-- EDIT --
To be honest, though, I would not store my connection string on my form like this. You'd be far better off storing it in an Application level variable, like so:
Application("CON_STRING") = "...blahblahblah..."
This should be stored in the Application_OnStart event of the Global.asa* file.
*
Apologies for the link to w3schools - it was the best at the time!
-- EDIT 2 --
Try using an iframe to display the info...
<form id="frmRender" action="ABCD/ReportServer?/Reports/rptSalesReport.rpt"; method="post" target="_blank">
<input type="hidden" name="rs:Command" value="Render">
<input type="hidden" name="rc:LinkTarget" value="_blank">
<input type="hidden" name="rs:Format" value="HTML4.0">
<input type="hidden" name="rc:Parameters" value="False">
<input type="hidden" name="ConnectionString" value="<%=Session("ConnectionString")%>">
<input type="hidden" name="StartDate" value="<%=StartDate%>">
<input type="hidden" name="EndDate" value="<%=EndDate%>">
<a id="linkInfo" href="javascript:generateSsrs();">Generate Report</a>
<iframe id="ssrsReport" class="reportHeightWidth"></iframe>
</form >
<script language="javascript">
function genreateSsrs() {
document.getElementById("ssrsReport").src = "ABCD/ReportServer?/Reports/rptSalesReport.rpt?rs:Command=Render&rc:LinkTarget=top&rs:Format=HTML4.0&rc:Parameters=False&ConnectionString=<%=Server.URLEncode(Session("ConnectionString"))%>&StartDate=<%=StartDate%>&EndDate=<%=EndDate%>";
}
</script>
That's a rough version, but it's untested, so may need some tweaks.
In you code, use the below code
="Data Source="+Parameters!DatabaseServerName.Value+";Initial Catalog="&Parameters!DatabaseCatalogName.Value

What URL should I use to PUT an update?

I have a Rails app that I just picked up that has the following command in "rake routes":
PUT /testclass/:id(.:format) testclass#update
I want to send a PUT update to this testclass with the id 18445 and change finished to false:
/18445&finished=false
for example.
My understanding is this should be able to be done by a HTTP request in the browser, for example, can it? Or do I need to use a Ruby command?
Any guidance?
You do not need to use a ruby command to access that route to make an update.
Basic HTML will look something like this (you can edit the action to be relevant to your route):
<form action='testclass/18445' method="post">
<input type="hidden" name="_method" value="put">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
<input type="hidden" name="testclass[id]" value="18445" >
<input type="hidden" name="testclass[finished]" value="false" >
<input type="submit" value="update" >
</form>
Notice it is a 'post' but there is a hidden input with the name '_method' and value 'put'. Hopefully this is what you're looking for. You can send your id through a hidden input, same with the false value.

asp.net mvc redirect to action and passing a parameter from user input

I have a page with a input box and a button, when the user clicks the button i want to redirect to a controller action that has as parameter the value of the input box.
<input id="CodProiect" type="text" />
<input id="Cauta" type="button" value="Cauta" onclick="window.location.href='#Url.Action("Cauta", "Componente", new { CodProiect = "param" })';"/>
How can i get the "param" from the input box ?
You could just use a form with a GET method
<form action="#Url.Action("Cauta", "Componente")" method="GET">
<input id="CodProiect" name="CodProiect" type="text" />
<input id="Cauta" type="submit" value="Cauta" />
</form>
The form will add the parameter as part of the query string of the URL e.g. www.yoursite.com/Cauta/Componente?CodProiect=user+entered+value
Value of the Action is prepared at server side and sent to the browser so you cannot have the value at the server when it is a user input.
You can use jquery to change the URL at client side.
Also passing state in an PRG scenario is a common problem in ASP NET MVC. You can either:
Store it temporarily in session
Pass it as a parameter in URL
Use a form.
Form:
<form action="Componente/Cauta">
<input id="CodProiect" type="text" />
<input id="Cauta" type="submit" value="Cauta" />
</form>
Controller:
public ActionResult Cauta(string CodProiect)
{
//Do some stuff
}
More info: http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx
Syntax may be outdated, but you get the point...

Handling 2 buttons submit Actions in a single View/Form - ASP.NET MVC 2 RTM

I have a View in which the user is able to upload a file to the server.
In this view I also have 2 buttons: one to Upload a file and other to Download the last file imported.
In my Controller I created 2 action methods: Import and Export.
How could I manage to redirect each button click to the proper action method in my Controller?
I have tried Html.ActionLink:
<%= Html.ActionLink("Upload", "Import", "OracleFile")%>
<%= Html.ActionLink("Download", "Export", "OracleFile")%>
Html.ActionLink didn't do the trick. The action links were taking me to the right Action methods but they were generating a GET request. This way Request.Files.Count = 0.
I need a POST request.
Note: the most intriguing part is that the upload was working and all of sudden it stopped working. I've seen that some people are having the same problem with FileUpload tasks in which the Request.Files is always Empty. I think it's empty because you need a post to the server. Isn't it?
maybe this will give u the idea:
view:
<form enctype="multipart/form-data" method="post" action="/Media/Upload/Photo">
<input type="file" name="file" id="file" />
<input type="submit" name= "submitImport" value="Upload" />
<input type="submit" name = "submitExport" value="Download" />
</form>
controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Action (FormCollection formCollection)
{
if (formCollection["submitImport"] != null)
{
return Import(formCollection);
}
if (formCollection["submitExport"] != null)
{
return Export(formCollection);
}
}
the Export and Import are the appropriateactions
You have to use a "multipart/form-data" form, and submit the form. No ActionLink.
<form enctype="multipart/form-data" method="post" action="/Media/Upload/Photo">
<input type="file" name="file" id="file" />
<input type="submit" value="Upload" />
</form>
To generate a POST request for the upload, use the File Input form element and just post back to the server ala normal.
http://www.w3schools.com/jsref/dom_obj_fileupload.asp
Have a look at this blog post from Scott Hanselman.
http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx

Resources