ASP.NET XML Control DocumentContent Property - asp.net

I am using ASP.NET XML control and on Page Load event I am updating its DocumentContent property but the problem is data isn't being shown. The control is empty on page load.
xmlDIMenuSource.DocumentContent = "<Menu><Parent ID="1" Name="Order" SortOrder="1"><Child ID="21" Name="Create an Order" URL="../Order/OrderCapturingv4.aspx?Action=new" SortOrder="1" /><Child ID="32" Name="Import a Style" URL="../Order/OrderCapturingv4.aspx?Action=import" SortOrder="2" /></Menu>";

Use valid XML. Plus, if this is VB.Net, you do not need the semi-colon at the end of the expression. Try this...
xmlDIMenuSource.DocumentContent = "<?xml version="1.0" encoding="utf-8" ?><Menu><Parent ID="1" Name="Order" SortOrder="1"><Child ID="21" Name="Create an Order" URL="../Order/OrderCapturingv4.aspx?Action=new" SortOrder="1" /><Child ID="32" Name="Import a Style" URL="../Order/OrderCapturingv4.aspx?Action=import" SortOrder="2" /></Parent></Menu>"

Related

using thymeleaf +spring to create custom tags (just like JSP)

I am trying to use Thymeleaf to create custom tags, just like in JSP.
The tag I have now is:
<select th:include="fragments/combobox :: combobox_beans (beans=${#accountService.getAccounts()}, innerHTML='id,description,currency', separator=' - ', dumbHtmlName='List of accounts', name='sender' )" th:remove="tag"></select>
The purpose is just defining the beans list, the properties of the bean to show on screen, the separator between them, the default value when shown as a native template, and the property name of the original bean we are processing here.
combobox.html:
<div th:fragment="combobox_beans (beans, innerHTML, separator, dumbHtmlName, name)">
<select th:field="*{__${name}__}" class="combobox form-control" required="required">
<option th:each="obj : ${beans}" th:with="valueAsString=${#strings.replace( 'obj.' + innerHTML, ',', '+'' __${separator}__ ''+ obj.')}"
th:value="${obj}" th:text="${valueAsString}" >
<p th:text="${dumbHtmlName}" th:remove="tag"></p>
</option>
</select>
I need the text of the option tag to be based on the properties set in innerHTML property (innerHTML='id,description,devise') of the fragment.
I end up having an option with this text:
<option value="...">obj.id+' - '+ obj.description+' - '+ obj.currency</option>
instead of the desired result
<option value="...">2 - primary - USD</option>
I know this is due to the usage of Strings library which results in a string.
Is there a way Thymeleaf can re-evaluate this string to be understood as an object again?
Maybe using strings library is just so wrong in this situation... Maybe I need to use a th:each to process the each bean as an object and read its properties, but yet again, how to only get the properties specified in innerHtml ?
Anyone has a solution or work-around for this ?
thanks.
If there is a way to do what you want in Thymeleaf/Spring expression alone, it most certainly very complicated and long winded, plus it would probably be a pain to read.
The easier way to do it would be add a custom utility object to the expression context. Very little code is needed. This answer shows it.
Then you need to add you new dialect as additional dialect to the template engine in your Spring xml config. Assuming you have a fairly standard Spring config, it should be similar to this.
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="additionalDialects">
<set>
<bean class="mypackage.MyUtilityDialect" />
</set>
</property>
</bean>
Now for the utility object
What you want is to get the properties from objects by name, and combine their values with a separator. It seems that the list of property names can be of any size. For accessing properties by name, the most convenient thing is to use a library like the Apache beanutils.
Your custom utility object could the look something like this using the Java 8 streams library, lambdas and Beanutils:
public class MyUtil {
public String joinProperties(Object obj, List<String> props, String separator){
return props.stream()
.map(p -> PropertyUtils.getProperty(obj,p).toString())
.collect(Collectors.joining(separator))
}
}
Then when you add you dialect to SpringTemplateEngine you can call your utility:
th:with="valueAsString=${#myutils.joinProperties(obj,properties,separator)}"
I have replaced you innerHTML parameter with properties which is a List<String>, because it makes more sense. It is essentially a list of property names, and Spring EL supports inline lists.
Your calling tag should then look like this.
<select th:include="fragments/combobox :: combobox_beans (beans=${#accountService.getAccounts()}, properties=${ {'id','description','currency'} }, separator=' - ', dumbHtmlName='List of accounts', name='sender' )" th:remove="tag"></select>

Custom report name in openerp

When I print my report, it display the name of the report like this
for selection of one record
"Delivery Slip-OUT_00057.pdf"
for selection of two record
"Delivery Slip-OUT_00057-OUT_00056.pdf"
SO for me, it is enough to show only
"Delivery Slip.pdf"
In both the cases, without editing in the base class
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="stock.report_picking_list_out"
model="stock.picking.out"
name="stock.picking.list.out"
string="Delivery Slip"
rml="XXXXX_stock_ext/report/delivery_slip.rml"
/>
</data>

Inject a simple string using unity property injection

I want to inject a string value into a property using Unity. I can't find a syntax that works. In this case, PutBunniesHere
In this case the error is it doesn't recognise "type" as a valid attribute of value. I added that because it couldn't resolve the type before.
The class has this property:
[Dependency("PutBunniesHere")]
public string PutBunniesHere { get; set; }
And this is the config I'm using for unity.
<?xml version="1.0" encoding="utf-8" ?>
<unity2 xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IInjectMe1" type="CommonLib.IInjectMe1, CommonLib"/>
<alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<container name="unity2">
<register type="CommonLib.IInjectMe2, CommonLib" name="Injected2" mapTo="CommonLib.InjectMe2, CommonLib">
<lifetime type="singleton"/>
<constructor>
<param name="theDependency" dependencyType="IInjectMe1" />
</constructor>
<property name="PutBunniesHere">
<value value="my bunnies" type="System.String"/>
</property>
</register>
</container>
</unity2>
Ok, solved the problem. Once again it was a problem with having a name on the register element. This makes value on the value element take on a different meaning. value means name of a registered type, or a type if there is a name attribute on the parent register element. Take out the name and value means a value (and possibly also a type)
Yuk.

Can I create a Razor view that renders Rss in asp.net mvc 3?

I know that to generate rss I can use built-in classes like SyndicationFeed and Rss20FeedFormatter. Also I know that it can be done with custom classes and aspx view.
But if I want to create custom feed objects and custom view, can I do this using razor?
Here is my view:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<h2>#Model.Title</h2>
<div><b>Description:</b> #Model.Description</div>
<div><b>Language:</b> #Model.Language</div>
Subscribe to this Feed
#foreach (var item in Model.Items)
{
<h3>
Title: #item.Title
</h3>
<div>
<img width="75" height="75" src="#Url.Action("GetImage", "Store", new { productId = item.ProductId })"/>
</div>
<div><b>Description:</b> #item.Description</div>
<div><b>Creator:</b> #item.Creator</div>
<div><b>Date published</b> #item.Published</div>
<div>
place order on Ozon
</div>
#Html.ActionLink("go to item", "ItemInformation", "Store", new {itemId = item.ItemId}, new {#class = "averageLink"})
}
</channel>
</rss>
Other questions:
1) I don't know how exactly to implement "subscription" link: what value to assign to the #Model.Url?
2) It generates html, mabby instead I need to serialize my feed objects into xml document and return it with a custom XmlResult : ActionResult?
Edit 1: Mabby I somehow can use built-in classes and custom feed model together?
Edit 2: The reason I don't want to use the existing classes is because I need to use Html.ActionLink() and Url.Action() helpers. If I serialize feed object into xml how would I use these helper methods?
Thanks for help in advance!
Your view code is producing html, not the xml that is needed for an rss feed (you are including elements like div and h3 that are part of html).
To produce a view that outputs RSS, the layout of the view should replicate the RSS standard.
For example:
#model MyProject.Models.RssModel
#{ Layout = null }
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>#model.FeedTitle</title>
<description>#model.FeedDescription</description>
<link>#model.FeedLink</link>
<lastBuildDate>#model.LastBuildDate</lastBuildDate>
<pubDate>#model.PubDate</pubDate>
<ttl>#model.Ttl</ttl>
#foreach (var item in Model.Items)
{
<item>
<title>#item.Title</title>
<description>#item.Description</description>
<link>#item.Url</link>
<guid>#item.Id</guid>
<pubDate>#item.PublicationDate</pubDate>
</item>
}
</channel>
</rss>
However, you may want to consider a different approach: returning a result from your Controller Action that will generate the RSS directly. You can see examples of this approach in this blog post or described in this answer.

Problem with setting the xml dataprovider for combo box

I am trying to get the drop down list of combobox by using a php file. That php file returns an xml string which has been used as data provider for combobox.
I followed this thread too but in vain.
Details
I have set the creationComplete attribute of mx:Application to init(). In the init() function i have sent the following HTTPService
<mx:HTTPService id="interfaces" url="interfaces.php" resultFormat="e4x" method="POST">
</mx:HTTPService>
Combo Box:
Update:
The xml should look like
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<ifaces>
<iface>
<option>eth0</option>
</iface>
<iface>
<option>eth1</option>
</iface>
</ifaces>
but if i execute interfaces.php in browser the only things that gets display is
eth0eth1
whereas i am echoing the string that contains whole xml data. Shouldn't whole xml type of string display? :(
The problem is that ifaces is the root element of your XML, so interfaces.lastResult == ifaces. So the XMLList you want is interfaces.lastResult.iface.
This is a whole main class that works for me:
`<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
initialize="{interfaces.send();}">
<mx:HTTPService id="interfaces" url="interfaces.xml" resultFormat="e4x" method="POST">
</mx:HTTPService>
<mx:ComboBox dataProvider="{interfaces.lastResult.iface}" labelField="option"/>
</mx:Application>`

Resources