Binding an inputText value to a viewScope with a computed name - data-binding

I have an inputText component on a custom control and I am trying to bind the value to a viewScope, but the viewScope name is computed using a compositeData value and string.
If I hardcode the value binding it works, for example:
value="${viewScope['BillingDate_From']}"
The viewScope name is computed using the following javascript code:
compositeData.dateRangeFilter[0].from_fieldname + '_From'
I have tried many ways of achieving this but with no success, sometimes it errors, usually unexpected character errors but most of the time the inputText box is empty.
The code I have most recently tried:
value="${viewScope[#{javascript:compositeData.dateRangeFilter[0].from_fieldname + '_From'}]}"

I have found, and I don't know the reason for this, that trying to bind dynamically doesn't work if there's any string concatenation in the evaluation. The way I got around this was by creating a custom control that accepts a bindingValue and dataSource as parameters, then passing in the document and field name I want to use. For whatever reason, if the code uses composite data, it still allows for editing when the page loads.

Hi try this to build what you need:
The Control:
<xp:inputText id="inputText1">
<xp:this.value><![CDATA[${javascript:"#{"+compositeData.scopeName+"}";}]]></xp:this.value>
</xp:inputText>
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[${javascript:"#{"+compositeData.scopeName+"}";}]]></xp:this.value>
</xp:text>
The XPage using the Control:
<xc:cc id="xx">
<xc:this.scopeName><![CDATA[#{javascript:return "viewScope." + " calculatedScopeVarName";}]]></xc:this.scopeName>
</xc:cc>
<xp:button value="Beschriftung" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="xx">
<xp:this.action><![CDATA[#{javascript://}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
Instead of "viewScope" you cant add session or another scope and instead of calculatedScopeVar you can enter the name of your var. But this has a limit, it only works if the calculatedScopeVar is accesable through the component onLoad. For example it will not work if you use this control in a Repeat control and try to use the repeated array as calculatedScopeVar.

Related

How to pass multiple server values to the web method when using AJAX Toolkit CascadingDropDowns

I need to pass in multiple server values to the web method.
If I pass through a single value in the ContextKey, like this:
ContextKey='<%# this.someValue.ToString()%>'”
I get the value, no problem.
But as soon as I try passing multiple variables, like this:
ContextKey='someKey1:<%# this.someValue1.ToString()%>;someKey2:<%#this.someValue2.ToString()%>'
I end up getting the literal string.
I used this post to get the syntax on how to pass multiple parameters:
http://selftaughtprogrammer.com/2012/11/01/how-to-pass-extra-parameters-when-using-ajax-toolkit-cascadingdropdowns-with-a-database/
Attribute values in ASP.NET markup can be either literals, or server-binded snippet, you cannot mix them in arbitrary order. However this is not a big deal, since server-binded snippet gives you everything need to form the necessary value. Say via string.Format:
ContextKey='<%# string.Format("someKey1:{0};someKey2:{1}", this.someValue1, this.someValue2) %>'

jqGrid: dataurl not working

I'm new to both jQuery and jQGrid. I tried to populate a dropdown combobox in the grid with data coming from server, I'm in java servlet environment.
I used dataUrl method and many others but still no luck with populating combo.
my js looks like:
...
{name:'idTipologia',index:'idTipologia', width:80,editable: true,edittype:"select",editoptions:{dataUrl: "/sohara/comboTipologiaAction.do"}...
...
my server side code basically is:
take a list from server, format data (whether json or not), open a PrintWriter, write info in it.
I tried both JSON conversion and plain text from Firebug I can see the response correctly formatted ("1:VALUE1;2:VALUE2")but the dropdown remains empty.
My question is:
Is there a peculiar way to organize the data in order to make this combo population?
Any help appreciated.
According to the jqGrid documentation, your problem is that the dataUrl needs to return HTML containing the SELECT element, not JSON:
The editoptions dataUrl parameter is valid only for element of edittype:select. The dataUrl parameter represent the url from where the html select element should be get.
When this option is set, the element will be filled with values from the AJAX request. The data should be a valid HTML select element with the desired options - something like:
<select>
<option value='1'>One</option>
<option value='2'>Two</option>
...
</select>
So the easiest solution is for you to just return HTML.
That said, I do not like the idea of returning UI elements directly. Another option is to use the buildSelect function to construct the SELECT element for you:
This option is relevant only if the dataUrl parameter is set. When the server response can not build the select element, you can use your own function to build the select. The function should return a string containing the select and options value(s) as described in dataUrl option. Parameter passed to this function is the server response
This answer provides an example of how to use buildSelect.

Resizing browser window in ActionScript

In my Flex page I have a link that navigates to different webpage and I want to control the size of that child webpage. For resizing, I am using JavaScript command within my ActionScript. Here is the ActionScript code:
private function openLinkEvent():void{
var baseUrl:String ="https://localhost:8080/someWebsite?customerName="customer.custName;
var jscommand:String ="window.open(baseUrl,'win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');";
var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(url, "_self");
}
I have 2 issues in this code:
If I do it with above mentioned way, new window is not opening and Flex page is showing error "baseUrl is undefined". Why I am not able to pass variable for my url instead of passing the url directly in window.open method?
If I directly pass the value of my baseURL("https://localhost:8080/someWebsite?customerName="customer.custName;) in window.open, it is taking value of customerName as customer.custName while it should take the real value of a customer saved in the session.
Just to clarify, when I pass baseUrl in following way, my application is working absolutely fine.
navigateToURL(new URLRequest(baseUrl))
But above command is not sufficient if I want to re-size the browser window. That is why I am using JS command integrated with ActionScript.
If I do it with above mentioned way, new window is not opening and
flex page is showing error "baseUrl is undefined". Why I am not able
to pass variable for my url instead of passing the url directly in
window.open method?
Well, baseUrl the variable is defined, however you are not using when creating your jsCommand. You are using a string entitled baseUrl; not the varibale.
This is what you have:
var jscommand:String ="window.open(baseUrl,'win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');";
This is probably what you want:
var jscommand:String ="window.open('" + baseUrl + "','win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');";
Use string concatenation to create your jscommand string. so that the resulting value for jscommand is this:
window.open('https://localhost:8080/someWebsite?customerName=something','win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');
Instead of this:
window.open(baseUrl,'win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');
Hopefully that makes sense.
If I directly pass the value of my
baseURL("https://localhost:8080/someWebsite?customerName="customer.custName;)
in window.open, it is taking value of customerName as
customer.custName while it should take the real value of a customer
saved in the session.
Well, it is odd that you're missing the concatenation operator when creating your baseURL. Add the + between your string and the customer.custName:
var baseUrl:String ="https://localhost:8080/someWebsite?customerName=" + customer.custName;
I'm surprised that line was not giving a compile time error. However, since you have not elaborated on what type of class customer is, nor what custName means, it's hard to give a definitive on what is going on here. I assume that customer is an instance of a custom class you built and that custName is string property on it.

How do I apply date formatting and add attributes to a textbox in MVC3?

In my application, I want all dates to display in the MM/DD/YYYY format and I also want the text box to be limited to 10 characters and have a certain class applied to it.
To that end, I made a custom editor template for Date that looks like this:
#ModelType System.Nullable(Of DateTime)
#Html.TextBoxFor(Function(d) d, New With {.class="polkDate", .maxlength="10"})
Then in my view I just can just call #Html.EditorFor(Function(m) m.someDate) and this works pretty well. However, because I'm using TextBoxFor, it doesn't respect the DisplayFormat attribute that's applied to my model class (i.e. it's spitting out the time as well instead of formatting the date).
I would love to use EditorFor so that it would respect the formatting that I want, but you can't add attributes like class and maxlength. I also tried just using the plain old TextBox helper, but I don't know how to make it generate the correct ID so that model binding still works.
Anybody know a way to make this happen? I don't feel like what I want to do here is too outlandish.
This appears to do the trick:
#ModelType Date
#If Date.MinValue.Equals(Model) Then
#Html.TextBox("", Nothing, New With {.class="polkDate", .maxlength="10"})
Else
#Html.TextBox("", Model.ToShortDateString(), New With {.class="polkDate", .maxlength="10"})
End If
Looks like the framework automatically assigns the ID and name fields of the html input tag so everything works properly.

passing querystring parameters

what is the best way of passing querystring to another page, i would definitly avoid like using.......
<a href="Page2.aspx?WONumber=12345">
is there any better way?
i was thinking create a Baseclass with few prop and update the baseclass?
thanks.
It sounds like you want to take the querystring argument, and use it in subsequent pages.
If it's not desirable to pass-forward this querystring argument from your current page, perhaps it's called page1.aspx, without using another querystring parameter, you could:
store the value in Session. Consider Session["WoNumber"] = Request.QueryString["WONumber"].ToString();
store the value in Cookies. You could use something like: Response.Cookies["WoNumber"].Value = Request.QueryString["WONumber"].ToString();
It really depends on where you're getting the value from. You can build a URL using UriBuilder or if it's simple enough string concatenation could be OK (though you'd have to make sure to Server.UrlEncode the values).
If the value is a constant, as your example implies, then there is nothing wrong with putting it directly into a query string, although I would still use a proper named constant, eg.
<a href="Page2.aspx?WONumber=<%= TheMagicOrderNumber %>
with the constant defined in the code-behind:
protected const int TheMagicOrderNumber = 12345
If your objection is the maintainability of "magic string" URLS, and you'd be prepared to use a button instead of an anchor, you could do worse than
<form method="GET" action="Page2.aspx">
<input type="hidden" name="WONumber" value="12345" />
<input type="submit" value="Navigate" />
</form>
this method will generalise to a query string of any complexity with any number of parameters.
There is a great article I came across a few months ago when I was looking for enhanced security with querystrings...
http://devcity.net/Articles/47/1/encrypt_querystring.aspx
It's a very good article, and has a bonus the author offers code examples in C# and VB.NET.
There are times when I prefer to use querystrings over sessions... small number of session objects is ok, but too many and it starts to become a bit tedious to debug problems.
You can encrypt a querystring parameter, if security is your concern.
Or you can use other holders, such s p.cambell says above (session & cookie).
You could also store it in a database, and have the page you go to retrieve it onload.
Just depends on your application requirements.
Another thing I've done is to use <asp:panel>, basically using a single page as though it were multiple pages. In this way, I also have access to viewstate to hold my variables. (Whenever a user clicks 'next', or whatever they would click to goto the next page, I simply hide the panel they're on, and show the panel they want to go to [visible = true/false] property)

Resources