Struts2 grid json - json

How can I exclude Hibernate objects that are listed as FetchType.LAZY? It causes problems because I get a org.hibernate.LazyInitializationException. I understand that it is trying to serialize the object and it can not because the session is closed. How can I disable it? I have many objects that do this and it would not be feasible to make them eager nor to remove them as there are too many of them. Please help.

I was able to use includeProperties as suggested by nmc, however it would still be nice to not have to define the properties and see if JSONUtil can just ignore lazy loaded objects.
<result name="success" type="json">
<param name="includeProperties"> ^gridModel\[\d+\]\.first, ^gridModel\[\d+\]\.last, rows, page, total, record</param>
</result>

In your struts.xml:
<result name="success" type="json">
<param name="excludeProperties">
<!-- insert comma separated parameters to be excluded here -->
</param>
</result>
Or you can also do an includeProperties. See http://struts.apache.org/2.2.3/docs/json-plugin.html for more details.

Related

Magento: Override phtml inside /base/default/template

I'm trying to override
app/design/frontend/base/default/template/contacts/form.phtml.
I followed several guides without success:
I can only post one link since I don't have enough reputation to post more :(
http://www.magento.scommerce-mage.co.uk/override-phtml-or-layout-core-files-in-magento.html
In fact I'm even more confused now since they are all using different approaches. At the moment I'm trying to do it like in the last guide since this is the most up to date one(2014) without success so far.
So here is what I got:
app/code/local/Namespace/MyModule/etc/config.xml
<config>
<frontend>
<layout>
<updates>
<contactredirect>
<file>contactredirect.xml</file>
</contactredirect>
</updates>
</layout>
</frontend>
</config>
app/design/frontend/base/default/layout/contactredirect.xml
<layout version="0.1.0">
<contacts_index_index translate="label">
<reference name="contacts.form">
<action method="setTemplate">
<template>contactredirect/form.phtml</template>
</action>
</reference>
</contacts_index_index>
</layout>
And finally the location of my form.phtml (the content probably doesn't matter):
app/design/frontend/base/default/template/contactredirect/form.phtml.
Any help is appreciated!
use "contactForm" in reference name ie code should be--
<reference name="contactForm">
<action method="setTemplate">
<template>contactredirect/form.phtml</template>
</action>
</reference>

NHibernate "Repeated column in mapping for collection" exception

Consider the following NHibernate mapping, and notice the commented properties. These are the same columns as the key and index column specified in the map. When I remove the comments (thus including the TypeOfPart and UnitId columns for the properties) I get the "Repeated column in mapping for collection" exception.
<map name="Parts" table="ActiveUnitParts" lazy="false">
<key column="UnitId" />
<index column="TypeOfPart" type="integer"/>
<composite-element class="ActiveUnitPart">
<property name="Id" />
<property name="CreationDate" />
<property name="PartInfo"/>
<property name="Remarks"/>
<!-- <property name="TypeOfPart" /> -->
<!-- <property name="UnitId" /> -->
</composite-element>
</map>
What I need in code is a Dictinonary<TypeOfpart, ActiveUnitPart>. But the problem I have is that the values for the properties UnitId and TypeOfPart aren't set in the ActiveUnitPart instance in the Dictinonary<TypeOfpart, ActiveUnitPart>.
Yes, the list of related parts of this unit is loaded, and yes the key in the dictionary is related to the right part. But I do not understand why I can not reference the TypeOfPart and UnitId to fill the properties in ActiveUnitPart itself as well.
How can I solve or workaround this?
Motivation of why I need this:
I must be able to work with ActiveUnitParts without referencing the related Unit (UnitId)
EDIT 1:
I know I can intercept the setter of the Parts property of the Unit and iterate through the Dictinonary<TypeOfpart, ActiveUnitPart> to set the values in code, but it seems like a hack and I wish to learn a more elegant NHibernate way of getting it done, if possible.
It is possible, just change the mapping from column to formula. The best way how to achieve that would be:
<property name="TypeOfPart" formula="TypeOfPart" insert="false" update="false" />
<property name="UnitId" formula="UnitId" insert="false" update="false" />

How do I get autocompletion for Flex Metadata?

I took a look at flex metadata and it seems to be quiet straight forward. Though I have a problem, I don't get autocompletion for the metadata.
I'll tell you what I did, maybe you find an error. I want to create my own Style metadata tag named e.g. MyStyle. I want to create my own because it's easier for me to determine at runtime if the metadata was added by me or by the flex framework (therefore I will not use the predefined Style metadata tag).
To add metadata is pretty simple, I just wrote this code to get it work:
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="1024" height="768">
<fx:Metadata>
[MyStyle(required="true")]
</fx:Metadata>
</s:Group>
On my WindowedApplication component I added an added to stage listener to the stage. So all elements that are added to the application will fire that Event.ADDED when they are added to the stage. In that eventHandler I scan added elements for my metadata tag.
protected function addedToStageListener(event:Event):void
{
var classInfo:XML = describeType(event.target);
for each (var x:XML in classInfo..metadata)
{
if (x.#name == "MyStyle")
trace(x);
}
}
I also added a flex-config.xml file (in the toplevel of my src folder) to add the compiler options, so that I can read my custom metadata tag on runtime. The file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<flex-config>
<compiler>
<keep-as3-metadata>
<name>MyStyle</name>
</keep-as3-metadata>
</compiler>
</flex-config>
When I run this, I get the result I expect
<metadata name="MyStyle">
<arg key="required" value="true"/>
</metadata>
So this works. My next step was to add autocompletion when adding the metadata tag to the code. To do this you should create a metadata.xml which specifies the metadata tags right?
So I did this and I ended up with this simple metadata.xml
<?xml version="1.0" encoding="UTF-8"?>
<annotations version="2.1.1">
<metadata name="MyStyle" description="Adds style.">
<context name="class" />
<attribute name="required" type="Boolean" required="true" />
</metadata>
</annotations>
To add the metadata.xml correctly to the project I followed that tutorial by Adobe, but it doesn't work. I don't get autocompletion. Do you have any suggestions?
Update: I use Flash Builder 4.6 Professional and I created a Flex Library Project.

"text-overflow: ellipsis;" in XUL applications

I'm writing an extension to an existing XUL-application, conkeror. In that, In
some part of the user-interface of I'm writing, I'm creating HTML elements with
a fixed-width, <span>s in this case, to display various results.
Within those spans there's text some text, which, on occasion, is too long to
fit its fixed-with container. I'd like to cut-off the parts that are too long,
and end it with an ellipsis instead.
Those spans currently have the following CSS attributes:
display: inline-block;
width: 30%;
overflow: hidden;
white-space: nowrap;
In addition to that, I'd like to use text-overflow: ellipsis;, but it turns
out the Gecko platform doesn't implement that yet. However, for plain HTML pages
with regular style-sheets, there happens to be a workaround for Firefox and
other Gecko-based products, that makes cutting off overlong text and putting an
ellipsis at its end work anyway.
The details of that technique are described
here. It's
using Gecko's ability to run XUL code to do its magic.
So I've tried to use that in my XUL application as well. I've changed my
style-sheet to include the described
-moz-binding: url('ellipsis.xml#ellipsis');, and also created the
elipsis.xml file as described.
However, doing this (or similar things using different URLs, e.g. chrome:// or
absolute file:// URLs) seems to have no effect whatsoever within my
application. In fact, it doesn't even try to access the ellipsis.xml file at
all, according to strace.
Obviously XUL is able to do what I want, so I'm assuming I'm doing something
wrong, or am simply missing out on some detail I have to take care of first in
order to get the desired results.
What I'm looking for is a way to pull the regular text-overflow: ellipsis;
track within a XUL application or, alternatively, a way to get the same result
without the aforementioned technique.
For some (maybe security) reason you need to use a chrome:// url in your CSS file. I tested it with conkeror 0.9.2 and xulrunner 1.9.1.
-moz-binding: url("chrome://conkeror/content/ellipsis.xml#ellipsis");
Where your ellipsis.xml is in /conkeror/install/path/modules/ (on debian /usr/share/conkeror/modules). You can check the chrome.manifest file to find the right location for your XML file, probably the style folder.
You said it´s not having ANY effect?
With
display:block; text-overflow:clip; overflow:hidden; white-space:nowrap;
it should at least cut off the text without the "...".
Is the reference to your xml file correct and your css and xml files are at the same path?
Also, try using this code:
<?xml version="1.0"?>
<bindings
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
>
<binding id="none">
<content><children/></content>
</binding>
<binding id="ellipsis">
<content>
<xul:label crop="end"><children/></xul:label>
</content>
<implementation>
<field name="label"> document.getAnonymousNodes( this )[ 0 ] </field>
<field name="style"> this.label.style </field>
<property name="display">
<getter>
this.style.display
</getter>
<setter>
if( this.style.display != val ) this.style.display= val
</setter>
</property>
<property name="value">
<getter>
this.label.value
</getter>
<setter>
if( this.label.value != val ) this.label.value= val
</setter>
</property>
<method name="update">
<body>
var strings= this.textContent.split( /\s+/g )
if( !strings[ 0 ] ) strings.shift()
if( !strings[ strings.length - 1 ] ) strings.pop()
this.value= strings.join( ' ' )
this.display= strings.length ? '' : 'none'
</body>
</method>
<constructor> this.update() </constructor>
</implementation>
<handlers>
<handler event="DOMSubtreeModified"> this.update() </handler>
</handlers>
</binding>
</bindings>

How to parse an .as (AS3) file

I am looking to get as close as I can to parsing out an AS3 file into objects or XML. For instance, imagine the following class:
package {
class SomeClass extends AnotherClass {
private var someVariable:Number
public function someMethod(someParameter:Number = 4):void {
var someLocalVariable:Number = someParameter * (2 + someVariable);
}
}
}
When parsed, it might be something like:
<package name="">
<class id="783" name="SomeClass" extendsId="782">
<variable id="784" visibility="private" type="Number"/>
<function id="785" name="someMethod" returnType="void">
<parameter id="786" name="someParameter" type="Number">
<expression>
<number value="4"/>
</expression>
</parameter>
<variable id="787" name="someLocalVariable" type="Number"/>
<code>
<assign toId="787">
<expression>
<variable id="786"/>
<operator type="*"/>
<expression>
<number value="2"/>
<operator type="+"/>
<variable id="786"/>
</expression>
</expression>
</assign>
</code>
</function>
</class>
</package>
.. even if I don't get a nice, neat xml structure like this, even if it could just parse AS3 to some kind of capacity, it would be way beyond where I am now.
Any thoughts?
Thanks,
Eric
I have actually ported the PMD parser to AS3.
You can check out http://github.com/teotigraphix/as3parser-framework
Mike
FlexPMD has an as3 parser. (FlexPMD is a Java project by Adobe that does reporting of best practices violations in as3 source code.)
FlexPMD is hosted at http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD
The code is on a subversion repo at http://opensource.adobe.com/svn/opensource/flexpmd/trunk
The down side is you would need to use Maven to build FlexPMD (me, I never managed to get it to work), but since you need just one or three projects, it might be possible to extract those by hand without too much cursing and shouting.
You may also want to wander further into the Flex SDK source code (also on opensource.adobe.com) to see if Adobe provides any other software for parsing as3,but I have not looked there.
There's a lexer, parser, and tokenizer in the AS3eval project:
AS3eval
Take a look at the flash.utils.describeType() documentation.
http://livedocs.adobe.com/flex/gumbo/langref/flash/utils/package.html#describeType()
It's for describe actionscript items at runtime, but should have some use in this case.