Using JSTL "dynamic" parameter name - servlets

JSTL Code:
<c:forEach var = "currentUser" items = "${users}">
<c:out value = "${currentUser.userName}" /></p>
<c:if test = "${!empty param.${currentUser.id}}">
<p>Details</p>
</c:if>
</c:forEach>
I have a list of user objects and i display all of their names. If one wants to see the details of any user a request is sent to a servlet which will return a Attribute with the name id and a DetailUser Object
Servlet:
req.setAttribute(currentUSer.getId, userDetails);
The problem is that, now if have to use the value of "id" in the if test not as a parameter, but a parameter name instead. I've tried that EL in EL expression but I am really sure that it isn't allowed. Any other suggestions?

It seems to me that you're making it more complex than it could be.I would simply do
req.setAttribute("userDetails", userDetails);
and, in the JSP, test if the current user's ID is the same as the one being detailed:
<c:if test="${userDetails.id == currentUser.id}">
<p>Details</p>
</c:if>
BTW, param.foo returns the value of a request parameter, not the value of a request attribute.
You could do what you wanted by using
<c:if test = "${!empty requestScope[currentUser.id]}">
The [] notation instead of the . operator is the way to pass a dynamic name rather than a static one.

Related

Displaying a JSON in a table ASP.Net MVC

I have a JWT that I want to display its contents after signature validation. so, I verify the signature like this:
var verified = JWT.Decode(token, publicKey);
In this case, verified is a string containing the JSON payload, looks something like this:
{"sub":"211668914321303","aud":"MUSCA","ver":"1.0.0","nbf":1544459925,"iss":"blimp gmbh","rle":"MUSCA_ACCESS","prm":"This chunk is bound to the something for blimp gmbh","exp":4703150773,"iat":1544459925,"jti":"46"}
now to view this on a page in form of a table, it's easier to send it as a JSON, and loop on its Type and Value, like this:
var verifiedJSON = JsonConvert.DeserializeObject(verified); //convert to JSON
ViewBag.payload = verifiedJSON
in my view, I loop on the ViewBag like this
<table class="table-bordered table-responsive">
#foreach (var line in ViewBag.payload)
{
<tr>
<td>#line.Type</td>
<td>#line.Value</td>
</tr>
}
I would expect that the table will show type and value in columns, but instead of the type(key), I get the word Property, with the expected value in each row!
I tried to display the JSON below the table to see if it came with "property" in the key fields, but it viewed with the correct key names. am I missing something or why can't I get the table to view the keys correctly?
I found the issue thanks to jabberwocky
I copied a table that was looping on an IEnumerable, and changed the variable which is a JSON, and by referring to Json.NET Documentation, I found out that the Key is not called Key or Type. It is called Name

Attach a csv file to work object

I have a XML file which I have to convert in CSV file and then attach in Work-Object?
I already tried by writing an activity and use pxConvertResultsToCSV activity and then try to attach file using Link Object method but by this all the result would come in a single row.
Few steps to be followed...
1) Parse the XML using activity method Apply-Parse-XML.
You will get the XML data in a PageList.
2) Now create on Rule-Obj-Html rule. In the code part create on table
<table border="1">
<pega:forEach name="YourPageListPage.PageList"> // --> the pagelist in which got the info from xml.
<tr>
<TD>
<pega:reference name="$THIS.COLUMN1"/> // --> property name
</TD>
<TD>
<pega:reference name="$THIS.COLUMN2"/> // --> property name 2
</TD>
</tr>
</pega:forEach>
</table>
3) Now using Property-Set-HTML get the stream of your html rule in some param variable(for example param.pyFileData)
Also create one local variable as strFileData.
Decode the stream Using Java step. And use this code.
String atr = (String)tools.getParameterPage().getParameterValue("pyFileData");
byte[] byteArray=(byte[])atr.getBytes();
//encode the byte array into Base64.
strFileData = Base64Util.encodeToString(byteArray); // strFileData is local variable mentioned in activity.
4) Now create a page of class Data-WorkAttach-File and set following properties on that page.
.pxRefObjectKey --> pzinskey of work object
.pxAttachKey --> any key, maybe current date time
.pyAttachStream --> your stream which you got from 3rd step (local.strFileData )
.pyNote --> any note
.pxAttachName --> "filename.csv"
Rest I guess already know..
Save this page using Obj-Save
5) Use Link-Objects to attach your attachment page to work object.
Thats it.

Pass values from default page to asp.net handler

I have a simple html hidden field as shown below
<input id="currentDirectory" type="hidden" runat="server" value="123"/>
Now I need to pass this hidden field value using query string to asp.net handler ans I have done as shown below but it dosen't pass the value.
In Default.aspx page:
var value = $("#currentDirectory").val();
url: 'Uploader.ashx?myvalue=' + value,
Accessing in Handler.ashx:
Dim myvar As String= System.Web.HttpContext.Current.Session("myvalue")
Can anyone say me where am I going wrong?

Linq call using anonymous/dynamic type does work in view

For the life of me I cannot figure out why this works. I'm simply calling some data via link and passing it on to the view. It works when I passe the data directly like this:
var invoices = (
from s in navdb.Sales_Invoice_Header
where s.Salesperson_Code == repCode
where s.Posting_Date > date
select s
).ToList();
But when I create an anonymous type on the fly it does not, like this:
var invoices = (
from s in navdb.Sales_Invoice_Header
where s.Salesperson_Code == repCode
where s.Posting_Date > date
select new {
s.No_,
s.Bill_to_Customer_No_,
s.Bill_to_Name,
s.Salesperson_Code
}
).ToList();
when accessing it like this after:
<table>
#foreach (var invoice in ViewBag.invoices)
{
<tr>
<td>#invoice.No_</td>
<td>#invoice.Bill_to_Customer_No_</td>
<td>#invoice.Bill_to_Name</td>
<td>#invoice.Salesperson_Code</td>
</tr>
}
</table>
I just get an: 'object' does not contain a definition for 'No_'
I've tried adding No_ = s.No_ and so forth, that does not help either. What am I doing wrong?
Duplicate question here: Dynamic Anonymous type in Razor causes RuntimeBinderException
The reason for this is that the anonymous type being passed in the
controller in internal, so it can only be accessed from within the
assembly in which it’s declared. Since views get compiled separately,
the dynamic binder complains that it can’t go over that assembly
boundary.
Basically, you can't bind against anonymous dynamic objects in this way. Define a specific class or struct to get around this.
In your first example, you're getting a List<whatever s is>, in your second example, you're getting a List<object>. And 'object' does not contain a definition for 'No_'

Retrieval of input type=password Request.Form["strPassword"] gives null

Are there any special considerations trying to read up data from an HTML form where the element is an input type="Password"? When a ColdFusion page POSTs my handler with form data I am getting null for the password instead of the typed value.
Here is the key line from the larger block below:
string password = context.Request.Form["strPassword"];
I have an HTTPHandler.ashx code file that performs an upload of a file when posted. Here is the key snippet of this code:
string username = context.Request.Form["strUsername"];
if (String.IsNullOrEmpty(username))
{
IdentifyInvoker = GetUserInfo();
brokerService = new Broker.FileService();
}
else
{
string password = context.Request.Form["strPassword"];
string domain = context.Request.Form["strDomain"];
IdentifyInvoker = GetInvokerInfoFromForm(username, password, domain);
brokerService = new Broker.FileService(username,password,domain);
}
The form from which the above code is posted (from ColdFusion) looks like this:
<b>User Name</b> <input type="text" name="strUsername" id="strUsername" size="13" />
<b>Password</b> <input type="Password" name="strPassword" id="strPassword" size="15" />
<b>Domain</b> <input type="text" name="strDomain" id="strDomain" size="13" value="cbmiweb" />
I was able to trap this with the debugger and was shocked to see that after this:
string password = context.Request.Form["strPassword"];
... password = null
In the immediate window, sure enough:
?context.Request.Form["strPassword"]
null
If I examine the entire Form collection in the debugger, I see the proper values laid out (separated by &) and none of the important data elements is null (but strangely the data contains a plus sign in front of the equal sign)! Here is a snippet from the immed window:
&strUsername=johna&strPassword+=xxxxxxxx&strDomain+=cbmiweb}
I have an ASP.NET client that POSTs to this same HTTPHandler and that works fine. Here the same form data shows without the interfering PLUS signs:
&strUsername=johna&strPassword=xxxxxxxx&strDomain=cbmiweb}
Any ideas on what causes this and how to retrieve the form data when it's formatted with the intervening PLUS signs?
EDIT:
Both the ASP.NET form and the ColdFusion form specify enctype="multipart/form-data" yet the latter embeds these PLUS signs.
Plus sign is the problem, it should not have been there, is your coldfusion forwarding request to your page or it is using its internal http request engine to do so?
Plus sign appears due to white space, please check in your coldfusion if any string concatenation caused white spaces to be inserted in your posted data?

Resources